internal static Party EditParty(PartyModel partyModel, Dictionary <string, string> partyCustomAttributeValues, IList <PartyRelationship> systemPartyRelationships) { using (PartyTypeManager partyTypeManager = new PartyTypeManager()) using (PartyManager partyManager = new PartyManager()) using (PartyRelationshipTypeManager partyRelationshipTypeManager = new PartyRelationshipTypeManager()) { var party = new Party(); var newAddPartyCustomAttrValues = new Dictionary <PartyCustomAttribute, string>(); party = partyManager.Find(partyModel.Id); //Update some fields party.Description = partyModel.Description; party.StartDate = partyModel.StartDate.HasValue ? partyModel.StartDate.Value : DateTime.MinValue; party.EndDate = partyModel.EndDate.HasValue ? partyModel.EndDate.Value : DateTime.MaxValue; party = partyManager.Update(party); foreach (var partyCustomAttributeValueString in partyCustomAttributeValues) { PartyCustomAttribute partyCustomAttribute = partyTypeManager.PartyCustomAttributeRepository.Get(int.Parse(partyCustomAttributeValueString.Key)); string value = string.IsNullOrEmpty(partyCustomAttributeValueString.Value) ? "" : partyCustomAttributeValueString.Value; newAddPartyCustomAttrValues.Add(partyCustomAttribute, value); } party.CustomAttributeValues = partyManager.AddPartyCustomAttributeValues(party, partyCustomAttributeValues.ToDictionary(cc => long.Parse(cc.Key), cc => cc.Value)).ToList(); return(party); } }
/// <summary> /// /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="description"></param> /// <param name="partyTypeId"></param> /// <param name="partyCustomAttributeValues">CustomAttributeName or Id as key</param> /// <returns></returns> internal static Party CreateParty(DateTime?startDate, DateTime?endDate, string description, long partyTypeId, Dictionary <string, string> partyCustomAttributeValuesDict) { using (PartyTypeManager partyTypeManager = new PartyTypeManager()) using (PartyManager partyManager = new PartyManager()) using (PartyRelationshipTypeManager partyRelationshipTypeManager = new PartyRelationshipTypeManager()) { var newParty = new Party(); PartyType partyType = partyTypeManager.PartyTypeRepository.Get(partyTypeId); var partyStatusType = partyTypeManager.GetStatusType(partyType, "Created"); // save party as temp if the reationships are required var requiredPartyRelationTypes = partyRelationshipTypeManager.GetAllPartyRelationshipTypes(partyType.Id).Where(cc => cc.MinCardinality > 0); //Create party newParty = partyManager.Create(partyType, "", description, startDate, endDate, partyStatusType, requiredPartyRelationTypes.Any()); partyManager.AddPartyCustomAttributeValues(newParty, toPartyCustomAttributeValues(partyCustomAttributeValuesDict, partyTypeId)); // partyManager.AddPartyRelationship(null,TargetPartyId,PartyTypePairid) //var systemPartyTypePairs = GetSystemTypePairs(newParty.PartyType.Id); ////add relationship to the all targets //foreach (var systemPartyTypePair in systemPartyTypePairs) //{ // foreach (var targetParty in systemPartyTypePair.TargetPartyType.Parties) // { // PartyTypePair partyTypePair = partyRelationshipTypeManager.PartyTypePairRepository.Reload(systemPartyTypePair); // partyManager.AddPartyRelationship(partyManager.PartyRepository.Reload(newParty), targetParty, "system", "", systemPartyTypePair, permission: systemPartyTypePair.PermissionTemplate); // } //} return(newParty); } }
internal static Party CreateParty(PartyModel partyModel, Dictionary <string, string> partyCustomAttributeValues) { PartyTypeManager partyTypeManager = new PartyTypeManager(); PartyManager partyManager = new PartyManager(); var party = new Party(); try { PartyType partyType = partyTypeManager.PartyTypeRepository.Get(partyModel.PartyType.Id); var partyStatusType = partyTypeManager.GetStatusType(partyType, "Created"); // save party as temp if the reationships are required var requiredPartyRelationTypes = new PartyRelationshipTypeManager().GetAllPartyRelationshipTypes(partyType.Id).Where(cc => cc.MinCardinality > 0); //Create party party = partyManager.Create(partyType, "", partyModel.Description, partyModel.StartDate, partyModel.EndDate, partyStatusType, requiredPartyRelationTypes.Any()); partyManager.AddPartyCustomAttributeValues(party, partyCustomAttributeValues.ToDictionary(cc => long.Parse(cc.Key), cc => cc.Value)); } finally { partyTypeManager?.Dispose(); partyManager?.Dispose(); } return(party); }