private void RemoveHouseholdMembersFromSupport(era_evacueesupport support, IEnumerable <era_householdmember> householdMembers) { foreach (var member in householdMembers) { essContext.DeleteLink(essContext.AttachOrGetTracked(nameof(EssContext.era_householdmembers), member, member => member.era_householdmemberid), nameof(era_householdmember.era_era_householdmember_era_evacueesupport), support); } }
private void UpdateSupport(era_evacuationfile file, era_evacueesupport support) { var existingSupport = essContext.era_evacueesupports .Where(s => s.era_name == support.era_name) .SingleOrDefault(); if (existingSupport == null) { throw new Exception($"Support {support.era_name} not found"); } if (existingSupport._era_evacuationfileid_value != file.era_evacuationfileid) { throw new Exception($"Support {support.era_name} not found in file {file.era_name}"); } essContext.LoadProperty(existingSupport, nameof(era_evacueesupport.era_era_householdmember_era_evacueesupport)); var currentHouseholdMembers = existingSupport.era_era_householdmember_era_evacueesupport.ToArray(); essContext.Detach(existingSupport); //foreach (var member in existingSupport.era_era_householdmember_era_evacueesupport) essContext.Detach(member); support.era_evacueesupportid = existingSupport.era_evacueesupportid; essContext.AttachTo(nameof(EssContext.era_evacueesupports), support); var teamMember = essContext.era_essteamusers.ByKey(support._era_issuedbyid_value).GetValue(); essContext.SetLink(support, nameof(era_evacueesupport.era_IssuedById), teamMember); essContext.UpdateObject(support); //remove household members no longer part of the support RemoveHouseholdMembersFromSupport(support, currentHouseholdMembers.Where(m => !support.era_era_householdmember_era_evacueesupport.Any(im => im.era_householdmemberid == m.era_householdmemberid))); //add household members to support AssignHouseholdMembersToSupport(support, support.era_era_householdmember_era_evacueesupport.Where(m => !currentHouseholdMembers.Any(im => im.era_householdmemberid == m.era_householdmemberid))); AssignSupplierToSupport(support); }
private void AssignSupplierToSupport(era_evacueesupport support) { if (support._era_supplierid_value.HasValue) { var supplier = essContext.era_suppliers.Where(s => s.era_supplierid == support._era_supplierid_value).SingleOrDefault(); if (supplier == null) { throw new ArgumentException($"Supplier id {support._era_supplierid_value} not found"); } essContext.SetLink(support, nameof(era_evacueesupport.era_SupplierId), supplier); } }
private void CreateSupport(era_evacuationfile file, era_evacueesupport support) { support.era_evacueesupportid = Guid.NewGuid(); essContext.AddToera_evacueesupports(support); essContext.AddLink(file, nameof(era_evacuationfile.era_era_evacuationfile_era_evacueesupport_ESSFileId), support); essContext.AddLink(file.era_CurrentNeedsAssessmentid, nameof(era_needassessment.era_era_needassessment_era_evacueesupport_NeedsAssessmentID), support); essContext.SetLink(support, nameof(era_evacueesupport.era_EvacuationFileId), file); essContext.SetLink(support, nameof(era_evacueesupport.era_NeedsAssessmentID), file.era_CurrentNeedsAssessmentid); var teamMember = essContext.era_essteamusers.Where(tu => tu.era_essteamuserid == support._era_issuedbyid_value).SingleOrDefault(); essContext.SetLink(support, nameof(era_evacueesupport.era_IssuedById), teamMember); AssignSupplierToSupport(support); AssignHouseholdMembersToSupport(support, support.era_era_householdmember_era_evacueesupport); }
public era_evacueesupport Convert(Support source, era_evacueesupport destination, ResolutionContext context) => source switch {