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); }
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); }
public PartyCustomGridColumns() { CustomAttribute = new PartyCustomAttribute(); TypePair = new PartyTypePair(); }
public PartyCustomAttributeValue() { CustomAttribute = new PartyCustomAttribute(); }