public static string GetValueFromSystem(long partyid, long targetElementId, LinkElementType targetElementType) { MappingManager _mappingManager = new MappingManager(); PartyTypeManager partyTypeManager = new PartyTypeManager(); PartyManager partyManager = new PartyManager(); try { using (IUnitOfWork uow = (new object()).GetUnitOfWork()) { string value = ""; IList <Entities.Mapping.Mapping> mapping = CachedMappings(); var mapping_result = mapping.Where(m => m.Target.ElementId.Equals(targetElementId) && m.Target.Type.Equals(targetElementType) && m.Source.Type.Equals(LinkElementType.PartyCustomType) ).ToList(); if (mapping_result.Any()) { string mask = ""; mask = mapping_result.FirstOrDefault().TransformationRule.Mask; foreach (var mapping_element in mapping_result) { long attributeId = mapping_element.Source.ElementId; PartyCustomAttributeValue attrValue = partyManager.PartyCustomAttributeValueRepository.Query() .Where(v => v.CustomAttribute.Id.Equals(attributeId) && v.Party.Id.Equals(partyid)) .FirstOrDefault(); if (attrValue != null) { List <string> regExResultList = transform(attrValue.Value, mapping_element.TransformationRule); string placeHolderName = attrValue.CustomAttribute.Name; mask = setOrReplace(mask, regExResultList, placeHolderName); } } if (mask.ToLower().Contains(value.ToLower())) { return(mask); } } } return(""); } finally { _mappingManager.Dispose(); partyTypeManager.Dispose(); partyManager.Dispose(); } }
//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(); // } // var partyCustomAttributeValues = Repo.Get(party.Id).CustomAttributeValues.ToList(); // if (!CheckUniqueness(party.PartyType, partyCustomAttributeValues, party)) // BexisException.Throw(party, String.Format("Due the party uniqueness policy for this party type this value couldn't save"), BexisException.ExceptionType.Edit, true); // return (entity); //} public bool RemovePartyCustomAttributeValue(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); //Uniqeness policy repo.Delete(entity); uow.Commit(); } partyCustomAttributeValue.Party = UpdatePartyName(partyCustomAttributeValue.Party); return(true); }
public PartyCustomAttributeValue UpdatePartyCustomAttributeValue(PartyCustomAttributeValue partyCustomAttributeValue, string newValue) { Contract.Requires(partyCustomAttributeValue != null && partyCustomAttributeValue.Id != 0, "Provided entities can not be null"); Contract.Ensures(Contract.Result <PartyCustomAttributeValue>() != null && Contract.Result <PartyCustomAttributeValue>().Id >= 0, "No entity is persisted!"); // Check uniqeness policy is not possible in single updating var entity = new PartyCustomAttributeValue(); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <PartyCustomAttributeValue> repo = uow.GetRepository <PartyCustomAttributeValue>(); entity = repo.Get(item => item.Id == partyCustomAttributeValue.Id).FirstOrDefault(); entity.Value = newValue; var partyCustomAttrVals = entity.Party.CustomAttributeValues.ToList(); partyCustomAttrVals.First(item => item.Id == entity.Id).Value = newValue; repo.Put(entity); // Merge is required here!!!! uow.Commit(); } entity.Party = UpdatePartyName(entity.Party); return(entity); }
/// <summary> /// /// </summary> /// <param name="party"></param> /// <param name="partyCustomAttributeValues"></param> /// <returns></returns> public IEnumerable <PartyCustomAttributeValue> AddPartyCustomAttributeValues(ref 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>(); IRepository <PartyCustomAttribute> repoCA = uow.GetRepository <PartyCustomAttribute>(); party = repo.Reload(party); if (!CheckUniqueness(repo, party.PartyType, partyCustomAttributeValues, party)) { BexisException.Throw(party, String.Format("Due the party uniqueness policy for this party type this value couldn't save"), BexisException.ExceptionType.Add, true); } foreach (var partyCustomAttributeValue in partyCustomAttributeValues) { //check if there is the same custom attribute for this party update it var entity = party.CustomAttributeValues.FirstOrDefault(item => item.CustomAttribute.Id == partyCustomAttributeValue.Key.Id); if (entity != null) { entity.Value = partyCustomAttributeValue.Value; } else { entity = new PartyCustomAttributeValue() { CustomAttribute = partyCustomAttributeValue.Key, Party = party, Value = partyCustomAttributeValue.Value }; party.CustomAttributeValues.Add(entity); } repoCAV.Put(entity); } uow.Commit(); } party = UpdatePartyName(party); return(party.CustomAttributeValues); }
public PartyCustomAttributeValue UpdatePartyCustomAttributeValues(List <PartyCustomAttributeValue> partyCustomAttributeValues) { Contract.Requires(partyCustomAttributeValues != null && partyCustomAttributeValues.Any(), "Provided entities can not be null"); Contract.Ensures(Contract.Result <PartyCustomAttributeValue>() != null && Contract.Result <PartyCustomAttributeValue>().Id >= 0, "No entity is persisted!"); if (!CheckUniqueness(this.PartyRepository, partyCustomAttributeValues, partyCustomAttributeValues.First().Party)) { BexisException.Throw(partyCustomAttributeValues.First(), String.Format("Due the party uniqueness policy for this party type this value couldn't save"), BexisException.ExceptionType.Edit, true); } var entity = new PartyCustomAttributeValue(); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <PartyCustomAttributeValue> repo = uow.GetRepository <PartyCustomAttributeValue>(); foreach (var partyCustomAttrVal in partyCustomAttributeValues) { entity = repo.Get(partyCustomAttrVal.Id); entity.Value = partyCustomAttrVal.Value; repo.Put(entity); // Merge is required here!!!! } uow.Commit(); } entity.Party = UpdatePartyName(entity.Party); return(entity); }
/// <summary> /// get all values from systen parties values /// /// </summary> /// <param name="mappings"></param> /// <returns></returns> private static List <string> getAllValuesFromSystem(IEnumerable <Entities.Mapping.Mapping> mappings, string value) { MappingManager _mappingManager = new MappingManager(); PartyTypeManager partyTypeManager = new PartyTypeManager(); PartyManager partyManager = new PartyManager(); List <string> tmp = new List <string>(); IEnumerable <long> parentIds = mappings.Where(m => m.Parent != null).Select(m => m.Parent.Id).Distinct(); IEnumerable <Entities.Mapping.Mapping> selectedMappings; // all Masks are the same string mask = ""; PartyType partyType = null; List <Party> parties = null; foreach (var pId in parentIds) { Entities.Mapping.Mapping parentMapping = _mappingManager.GetMapping(pId); selectedMappings = mappings.Where(m => m.Parent != null && m.Parent.Id.Equals(pId)); long parentTypeId = parentMapping.Source.ElementId; long sourceId = selectedMappings.FirstOrDefault().Source.ElementId; //mappings.FirstOrDefault().TransformationRule.Mask; if (parentTypeId == 0) { partyType = partyTypeManager.PartyTypeRepository.Query() .FirstOrDefault(p => p.CustomAttributes.Any(c => c.Id.Equals(sourceId))); parties = partyManager.PartyRepository.Get().Where(p => p.PartyType.Equals(partyType)).ToList(); } else { partyType = partyTypeManager.PartyTypeRepository.Get(parentTypeId); parties = partyManager.PartyRepository.Get().Where(p => p.PartyType.Id.Equals(parentTypeId)).ToList(); } if (parties != null) { foreach (var p in parties) { mask = mappings.FirstOrDefault().TransformationRule.Mask; foreach (var mapping in mappings) { long attributeId = mapping.Source.ElementId; PartyCustomAttributeValue attrValue = partyManager.PartyCustomAttributeValueRepository.Get() .Where(v => v.CustomAttribute.Id.Equals(attributeId) && v.Party.Id.Equals(p.Id)) .FirstOrDefault(); List <string> regExResultList = transform(attrValue.Value, mapping.TransformationRule); string placeHolderName = attrValue.CustomAttribute.Name; mask = setOrReplace(mask, regExResultList, placeHolderName); } if (mask.ToLower().Contains(value.ToLower())) { tmp.Add(mask); } } } } return(tmp); }