internal static bool NewDiseaseValidation(AsSession session, AsSessionDisease item) { //check duplicates if (session.Diseases.Count(x => x.idfMonitoringSessionToDiagnosis != item.idfMonitoringSessionToDiagnosis && x.idfsDiagnosis == item.idfsDiagnosis && x.idfsSpeciesType == item.idfsSpeciesType && x.idfsSampleType == item.idfsSampleType && !x.IsMarkedToDelete) > 0) { throw new ValidationModelException("AsSession.Diseases.Duplicate_msgId", "idfsSpeciesType", "idfsSpeciesType", null, typeof(PredicateValidator), ValidationEventType.Error, session); } /*if (session.idfCampaign.HasValue && session.Parent == null && session.CampaignInRamOnly == null) * { * using (DbManagerProxy manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance)) * { * session.CampaignInRamOnly = AsCampaign.Accessor.Instance(null).SelectByKey(manager, session.idfCampaign); * } * }*/ if (session.idfCampaign.HasValue && session.CampaignInRamOnly != null && session.CampaignInRamOnly.Diseases.Where(d => !d.IsMarkedToDelete).Count(d => d.idfsDiagnosis == item.idfsDiagnosis && (d.idfsSpeciesType == item.idfsSpeciesType || !d.idfsSpeciesType.HasValue) && (d.idfsSampleType == item.idfsSampleType || !d.idfsSampleType.HasValue)) == 0) { string diagnosis = item.Diagnosis.name; string sample = item.SampleType == null ? "" : ": " + Utils.InsertSeparator("/", item.SampleType.name); string species = item.SpeciesType == null ? "" : ": " + Utils.InsertSeparator("/", item.SpeciesType.name); throw new ValidationModelException("msgCantAddSessionDiagnosis", "idfCampaign", "idfCampaign", new object[] { diagnosis, species, sample }, null, ValidationEventType.Error, session); } return(true); }
public static void CopyDiseasesFromCampaignToSession(DbManagerProxy manager, AsSession session, AsCampaign campaign) { foreach (var sessionDisease in session.Diseases.Where(d => !d.IsMarkedToDelete)) { sessionDisease.DeleteNoValidate(false); } if (campaign.Diseases.Count(x => !x.IsMarkedToDelete) > 0 && session.Diseases.Count(x => !x.IsMarkedToDelete) == 0) { AsSessionDisease item = null; foreach (var campaignDisease in campaign.Diseases.Where(d => !d.IsMarkedToDelete)) { item = (AsSessionDisease)AsSessionDisease.Accessor.Instance(null).CreateNew(manager, session); item.idfMonitoringSession = session.idfMonitoringSession; //item.idfsDiagnosis = campaignDisease.idfsDiagnosis; //item.idfsSpeciesType = campaignDisease.idfsSpeciesType; item.Diagnosis = item.DiagnosisLookup.FirstOrDefault(c => c.idfsDiagnosis == campaignDisease.idfsDiagnosis); item.SpeciesType = item.SpeciesTypeLookup.FirstOrDefault(c => c.idfsBaseReference == campaignDisease.idfsSpeciesType); item.SampleType = item.SampleTypeLookup.FirstOrDefault(c => c.idfsReference == campaignDisease.idfsSampleType); session.Diseases.Add(item); } } }