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

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

public AddPartyCustomAttriuteValue ( Party party, string>.Dictionary partyCustomAttributeValues ) : IEnumerable
party BExIS.Dlm.Entities.Party.Party
partyCustomAttributeValues string>.Dictionary
Результат IEnumerable
        public IEnumerable<PartyCustomAttributeValue> AddPartyCustomAttriuteValue(PartyX party, Dictionary<PartyCustomAttribute, string> partyCustomAttributeValues)
        {
            Contract.Requires(partyCustomAttributeValues != null);
            Contract.Requires(party != null);
            Contract.Requires(party.Id >= 0, "Provided party entity must have a permanent ID");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyX> repo = uow.GetRepository<PartyX>();
                IRepository<PartyCustomAttributeValue> repoCAV = uow.GetRepository<PartyCustomAttributeValue>();
                party = repo.Reload(party);

                foreach (var partyCustomAttributeValue in partyCustomAttributeValues)
                {
                    //check if there is the same custom attribute for this party update it
                    var similarPartyCustomAttr = party.CustomAttributeValues.FirstOrDefault(item => item.CustomAttribute.Id == partyCustomAttributeValue.Key.Id);
                    if (similarPartyCustomAttr != null)
                        similarPartyCustomAttr.Value = partyCustomAttributeValue.Value;
                    else
                    {
                        var entity = new PartyCustomAttributeValue()
                        {
                            CustomAttribute = partyCustomAttributeValue.Key,
                            Party=party,
                            Value = partyCustomAttributeValue.Value
                        };

                        repoCAV.Put(entity);
                    }
                }
                uow.Commit();
            }
            return party.CustomAttributeValues;
        }

Same methods

PartyManager::AddPartyCustomAttriuteValue ( Party party, PartyCustomAttribute partyCustomAttribute, string value ) : PartyCustomAttributeValue

Usage Example

Пример #1
0
        public ActionResult Create(PartyModel partyModel, Dictionary<string, string> partyCustomAttributeValues)
        {
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            PartyManager partyManager = new PartyManager();
            validateAttribute(partyModel);
            if (partyModel.Errors.Count > 0)
                return View(partyModel);
            //
            var partyType = partyTypeManager.Repo.Get(partyModel.Party.PartyType.Id);
            var partyStatusType = partyTypeManager.GetStatusType(partyType, "Create");

            //Create party
            var party = partyManager.Create(partyType, partyModel.Party.Name, "", "", partyModel.Party.StartDate, partyModel.Party.EndDate, partyStatusType);
            //Add customAttriuteValue to party
            partyManager.AddPartyCustomAttriuteValue(party, ConvertDictionaryToPartyCustomeAttrValuesDictionary(partyCustomAttributeValues));
            return RedirectToAction("Index");
        }