BExIS.Dlm.Services.Party.PartyManager.UpdatePartyCustomAttriuteValue C# (CSharp) Метод

UpdatePartyCustomAttriuteValue() публичный Метод

public UpdatePartyCustomAttriuteValue ( PartyCustomAttribute partyCustomAttribute, Party party, string value ) : PartyCustomAttributeValue
partyCustomAttribute BExIS.Dlm.Entities.Party.PartyCustomAttribute
party BExIS.Dlm.Entities.Party.Party
value string
Результат BExIS.Dlm.Entities.Party.PartyCustomAttributeValue
        public PartyCustomAttributeValue UpdatePartyCustomAttriuteValue(PartyCustomAttribute partyCustomAttribute,PartyX party,string value)
        {
            Contract.Requires(partyCustomAttribute != null && party != null, "Provided entities can not be null");
            Contract.Requires(partyCustomAttribute.Id >= 0 && party.Id >= 0, "Provided entitities must have a permanent ID");
            Contract.Ensures(Contract.Result<PartyCustomAttributeValue>() != null && Contract.Result<PartyCustomAttributeValue>().Id >= 0, "No entity is persisted!");
            var entity = new PartyCustomAttributeValue();
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyCustomAttributeValue> repo = uow.GetRepository<PartyCustomAttributeValue>();
                entity = repo.Get(item => item.Party.Id == party.Id && item.CustomAttribute.Id == partyCustomAttribute.Id).FirstOrDefault();
                entity.Value = value;
                repo.Put(entity); // Merge is required here!!!!
                uow.Commit();
                entity = repo.Reload(entity);
            }
            return (entity);
        }

Usage Example

Пример #1
0
 public ActionResult Edit(PartyModel partyModel, Dictionary<string, string> partyCustomAttributeValues)
 {
     using (IUnitOfWork uow = this.GetUnitOfWork())
     {
         PartyTypeManager partyTypeManager = new PartyTypeManager();
         PartyManager partyManager = new PartyManager();
         validateAttribute(partyModel);
         if (partyModel.Errors.Count > 0)
             return View(partyModel);
         var party = partyManager.Repo.Reload(partyModel.Party);
         //Update some fields
         party.Description = partyModel.Party.Description;
         party.StartDate = partyModel.Party.StartDate;
         party.EndDate = partyModel.Party.EndDate;
         party.Name = partyModel.Party.Name;
         party = partyManager.Update(party);
         foreach (var partyCustomAttributeValueString in partyCustomAttributeValues)
         {
             var partyCustomAttribute = partyTypeManager.RepoPartyCustomAttribute.Get(int.Parse(partyCustomAttributeValueString.Key));
             partyManager.UpdatePartyCustomAttriuteValue(partyCustomAttribute, partyModel.Party, partyCustomAttributeValueString.Value);
         }
     }
     return RedirectToAction("Index");
 }