/// <summary> /// Assembles and returns the list of SiteWaveDetails that are not referenced by any SiteFractionDetails /// </summary> /// <param name="pm"></param> /// <param name="revisionedSite"></param> /// <returns></returns> private static IEnumerable <SiteWaveDetails> GetUnreferencedSiteWaveDetails(ImpacPersistenceManager pm, PrescriptionSite revisionedSite) { var swdEntitiesToRemove = new List <SiteWaveDetails>(); List <SiteFractionDetails> sfdEntitiesSurviving = pm.GetAllEntitiesInCache().OfType <SiteFractionDetails>() .Where(e => e.SIT_ID == revisionedSite.SIT_ID && e.Seq <= revisionedSite.Fractions) .ToList(); List <SiteWaveDetails> swdEntities = pm.GetAllEntitiesInCache().OfType <SiteWaveDetails>() .Where(e => e.SIT_ID == revisionedSite.SIT_ID) .ToList(); // Assemble the list of SiteWaveDetails that are not referenced by any SiteFractionDetails records that will survive this update foreach (SiteWaveDetails swdEntity in swdEntities) { var swdId = swdEntity.SWD_ID; if (sfdEntitiesSurviving.Count(e => e.SWD_ID == swdId) == 0) { swdEntitiesToRemove.Add(swdEntity); } } return(swdEntitiesToRemove); }
/// <summary> /// Remove from the persistence manager or mark for deletion the excess SiteFractionDetails records, if there are any. /// (There aren't necessarily any SiteFractionDetails records for the Site.) /// If a SiteFractionDetails record is to be removed/deleted and it contains a link to a Notes record /// which is referenced by no other SiteFractionDetails record then mark it for deletion. /// </summary> /// <param name="pm"></param> /// <param name="revisionedSite"></param> private static void RemoveExcessSiteFractionDetailsAndNotes(ImpacPersistenceManager pm, PrescriptionSite revisionedSite) { List <SiteFractionDetails> sfdsToRemove = pm.GetAllEntitiesInCache().OfType <SiteFractionDetails>() .Where(e => e.SIT_ID == revisionedSite.SIT_ID && e.Seq > revisionedSite.Fractions) .ToList(); if (sfdsToRemove.Count > 0) { if (revisionedSite.SIT_ID > 0) { // A version roll will NOT occur // Remove fraction-specific notes that will be orphaned (if any) when the excess fractions are removed // (No fraction-specific notes will be orphaned when there is a version roll // - they'll still be referenced from the about-to-be historic rx fx detail recs) RemoveFxNotesThatWillBeOrphaned(pm, sfdsToRemove, revisionedSite); } // Mark for deletion the excess fraction detail records sfdsToRemove.Delete(); } }