BExIS.Dlm.Services.Party.PartyManager.Update C# (CSharp) Method

Update() public method

public Update ( Party entity ) : Party
entity BExIS.Dlm.Entities.Party.Party
return BExIS.Dlm.Entities.Party.Party
        public PartyX Update(PartyX entity)
        {
            Contract.Requires(entity != null, "Provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "Provided entity must have a permanent ID");
            Contract.Ensures(Contract.Result<PartyX>() != null && Contract.Result<PartyX>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyX> repo = uow.GetRepository<PartyX>();
                repo.Put(entity); // Merge is required here!!!!
                uow.Commit();
                entity = repo.Reload(entity);
            }
            return (entity);
        }

Usage Example

コード例 #1
0
ファイル: PartyController.cs プロジェクト: BEXIS2/Core
 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");
 }