Esempio n. 1
0
        public PartyCustomAttributeValue AddPartyCustomAttriuteValue(PartyX party, PartyCustomAttribute partyCustomAttribute, string value)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(value));
            Contract.Requires(partyCustomAttribute != null);
            Contract.Requires(partyCustomAttribute.Id >= 0, "Provided Custom Attribute entity must have a permanent identifier.");
            Contract.Requires(party != null);
            Contract.Requires(party.Id >= 0, "Provided party entity must have a permanent ID");

            Contract.Ensures(Contract.Result<PartyCustomAttributeValue>() != null && Contract.Result<PartyCustomAttributeValue>().Id >= 0);

            var entity = new PartyCustomAttributeValue()
            {
                CustomAttribute = partyCustomAttribute,
                Value = value
            };
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyX> repo = uow.GetRepository<PartyX>();
                IRepository<PartyCustomAttributeValue> repoCAV = uow.GetRepository<PartyCustomAttributeValue>();
                var partyEntity = repo.Reload(party);
                //if there is no attribute value when it created
                if (partyEntity.CustomAttributeValues == null)
                    partyEntity.CustomAttributeValues = new List<PartyCustomAttributeValue>();
                //check if there is the same custom attribute for this party update it
                var similarPartyCustomAttr = partyEntity.CustomAttributeValues.FirstOrDefault(item => item.CustomAttribute.Id == partyCustomAttribute.Id);
                if (similarPartyCustomAttr != null)
                {
                    similarPartyCustomAttr.Value = value;
                    entity = similarPartyCustomAttr;
                }
                else
                {
                    partyEntity.CustomAttributeValues.Add(entity);
                    repoCAV.Put(entity);
                }
                uow.Commit();
            }
            return (entity);
        }
Esempio n. 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="party"></param>
        /// <param name="partyCustomAttributeValues"></param>
        /// <returns></returns>
        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;
        }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 public bool RemovePartyCustomAttriuteValue(PartyCustomAttributeValue partyCustomAttributeValue)
 {
     Contract.Requires(partyCustomAttributeValue != null);
     Contract.Requires(partyCustomAttributeValue.Id >= 0, "Provided entity must have a permanent ID");
     using (IUnitOfWork uow = this.GetUnitOfWork())
     {
         IRepository<PartyCustomAttributeValue> repo = uow.GetRepository<PartyCustomAttributeValue>();
         var entity = repo.Reload(partyCustomAttributeValue);
         repo.Delete(entity);
         uow.Commit();
     }
     return (true);
 }