public async Task <ActionResult> Save(SamplingPlanViewModel model) { using (SamplingPlanServiceClient client = new SamplingPlanServiceClient()) { SamplingPlan obj = new SamplingPlan() { Key = model.Name.ToUpper(), Status = model.Status, Size = model.Size, Mode = model.Mode, Type = model.Type, Description = model.Description, Editor = User.Identity.Name, EditTime = DateTime.Now, CreateTime = DateTime.Now, Creator = User.Identity.Name }; MethodReturnResult rst = await client.AddAsync(obj); if (rst.Code == 0) { rst.Message = string.Format(EDCResources.StringResource.SamplingPlan_Save_Success , model.Name); } return(Json(rst)); } }
/// <summary> /// add as an asynchronous operation. /// </summary> /// <param name="obj">The object.</param> /// <returns>Task<MethodReturnResult>.</returns> public async Task <MethodReturnResult> AddAsync(SamplingPlan obj) { return(await Task.Run <MethodReturnResult>(() => { return base.Channel.Add(obj); })); }
public void SamplingPlanAndFilesLabSheetCount_Every_Property_Has_Get_Set_Test() { int val1 = 45; samplingPlanAndFilesLabSheetCount.LabSheetHistoryCount = val1; Assert.AreEqual(val1, samplingPlanAndFilesLabSheetCount.LabSheetHistoryCount); int val2 = 45; samplingPlanAndFilesLabSheetCount.LabSheetTransferredCount = val2; Assert.AreEqual(val2, samplingPlanAndFilesLabSheetCount.LabSheetTransferredCount); SamplingPlan val3 = new SamplingPlan(); samplingPlanAndFilesLabSheetCount.SamplingPlan = val3; Assert.AreEqual(val3, samplingPlanAndFilesLabSheetCount.SamplingPlan); TVFile val4 = new TVFile(); samplingPlanAndFilesLabSheetCount.TVFileSamplingPlanFileTXT = val4; Assert.AreEqual(val4, samplingPlanAndFilesLabSheetCount.TVFileSamplingPlanFileTXT); bool val5 = true; samplingPlanAndFilesLabSheetCount.HasErrors = val5; Assert.AreEqual(val5, samplingPlanAndFilesLabSheetCount.HasErrors); IEnumerable <ValidationResult> val18 = new List <ValidationResult>() { new ValidationResult("First CSSPError Message") }.AsEnumerable(); samplingPlanAndFilesLabSheetCount.ValidationResults = val18; Assert.AreEqual(val18, samplingPlanAndFilesLabSheetCount.ValidationResults); }
public void SamplingPlan_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { SamplingPlanController samplingPlanController = new SamplingPlanController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(samplingPlanController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanController.DatabaseType); SamplingPlan samplingPlanLast = new SamplingPlan(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; SamplingPlanService samplingPlanService = new SamplingPlanService(query, db, ContactID); samplingPlanLast = (from c in db.SamplingPlans select c).FirstOrDefault(); } // ok with SamplingPlan info IHttpActionResult jsonRet = samplingPlanController.GetSamplingPlanWithID(samplingPlanLast.SamplingPlanID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <SamplingPlan> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlan>; SamplingPlan samplingPlanRet = Ret.Content; Assert.AreEqual(samplingPlanLast.SamplingPlanID, samplingPlanRet.SamplingPlanID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = samplingPlanController.Put(samplingPlanRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <SamplingPlan> samplingPlanRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlan>; Assert.IsNotNull(samplingPlanRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because SamplingPlanID of 0 does not exist samplingPlanRet.SamplingPlanID = 0; IHttpActionResult jsonRet3 = samplingPlanController.Put(samplingPlanRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <SamplingPlan> samplingPlanRet3 = jsonRet3 as OkNegotiatedContentResult <SamplingPlan>; Assert.IsNull(samplingPlanRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
public IHttpActionResult GetSamplingPlanWithID([FromUri] int SamplingPlanID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { SamplingPlanService samplingPlanService = new SamplingPlanService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); samplingPlanService.Query = samplingPlanService.FillQuery(typeof(SamplingPlan), lang, 0, 1, "", "", extra); if (samplingPlanService.Query.Extra == "A") { SamplingPlanExtraA samplingPlanExtraA = new SamplingPlanExtraA(); samplingPlanExtraA = samplingPlanService.GetSamplingPlanExtraAWithSamplingPlanID(SamplingPlanID); if (samplingPlanExtraA == null) { return(NotFound()); } return(Ok(samplingPlanExtraA)); } else if (samplingPlanService.Query.Extra == "B") { SamplingPlanExtraB samplingPlanExtraB = new SamplingPlanExtraB(); samplingPlanExtraB = samplingPlanService.GetSamplingPlanExtraBWithSamplingPlanID(SamplingPlanID); if (samplingPlanExtraB == null) { return(NotFound()); } return(Ok(samplingPlanExtraB)); } else { SamplingPlan samplingPlan = new SamplingPlan(); samplingPlan = samplingPlanService.GetSamplingPlanWithSamplingPlanID(SamplingPlanID); if (samplingPlan == null) { return(NotFound()); } return(Ok(samplingPlan)); } } }
private bool TryToSave(SamplingPlan samplingPlan) { try { db.SaveChanges(); } catch (DbUpdateException ex) { samplingPlan.ValidationResults = new List <ValidationResult>() { new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : "")) }.AsEnumerable(); return(false); } return(true); }
public bool Update(SamplingPlan samplingPlan) { samplingPlan.ValidationResults = Validate(new ValidationContext(samplingPlan), ActionDBTypeEnum.Update); if (samplingPlan.ValidationResults.Count() > 0) { return(false); } db.SamplingPlans.Update(samplingPlan); if (!TryToSave(samplingPlan)) { return(false); } return(true); }
public void SamplingPlan_Controller_GetSamplingPlanWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { SamplingPlanController samplingPlanController = new SamplingPlanController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(samplingPlanController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanController.DatabaseType); SamplingPlan samplingPlanFirst = new SamplingPlan(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { SamplingPlanService samplingPlanService = new SamplingPlanService(new Query(), db, ContactID); samplingPlanFirst = (from c in db.SamplingPlans select c).FirstOrDefault(); } // ok with SamplingPlan info IHttpActionResult jsonRet = samplingPlanController.GetSamplingPlanWithID(samplingPlanFirst.SamplingPlanID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <SamplingPlan> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlan>; SamplingPlan samplingPlanRet = Ret.Content; Assert.AreEqual(samplingPlanFirst.SamplingPlanID, samplingPlanRet.SamplingPlanID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = samplingPlanController.GetSamplingPlanWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <SamplingPlan> samplingPlanRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlan>; Assert.IsNull(samplingPlanRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
public IHttpActionResult Delete([FromBody] SamplingPlan samplingPlan, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { SamplingPlanService samplingPlanService = new SamplingPlanService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!samplingPlanService.Delete(samplingPlan)) { return(BadRequest(String.Join("|||", samplingPlan.ValidationResults))); } else { samplingPlan.ValidationResults = null; return(Ok(samplingPlan)); } } }
private void SendNewLabSheetEmailBigMPN(string href, TVItem tvItemProvince, TVItem tvItemSubsector, LabSheetAndA1Sheet labSheetAndA1Sheet) { using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerCSSPDB)) { SamplingPlan samplingPlan = (from c in db.SamplingPlans where c.SamplingPlanID == labSheetAndA1Sheet.LabSheet.SamplingPlanID select c).FirstOrDefault(); List <SamplingPlanEmail> SamplingPlanEmailList = (from c in db.SamplingPlanEmails where c.SamplingPlanID == samplingPlan.SamplingPlanID orderby c.Email select c).ToList(); if (!samplingPlan.IsActive) { return; } // sending email to Contractors and Non Contractors foreach (bool IsContractor in new List <bool> { false, true }) { MailMessage mail = new MailMessage(); foreach (SamplingPlanEmail samplingPlanEmail in SamplingPlanEmailList.Where(c => c.IsContractor == IsContractor && c.LabSheetHasValueOver500 == true)) { mail.To.Add(samplingPlanEmail.Email.ToLower()); } if (mail.To.Count == 0) { continue; } mail.From = new MailAddress("*****@*****.**"); mail.IsBodyHtml = true; SmtpClient myClient = new System.Net.Mail.SmtpClient(); myClient.Host = "smtp.email-courriel.canada.ca"; myClient.Port = 587; myClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "H^9h6g@Gy$N57k=Dr@J7=F2y6p6b!T"); myClient.EnableSsl = true; mail.Priority = MailPriority.High; string TVTextSubsector = (from c in db.TVItemLanguages where c.TVItemID == tvItemSubsector.TVItemID && c.Language == LanguageEnum.en select c.TVText).FirstOrDefault(); if (string.IsNullOrWhiteSpace(TVTextSubsector)) { TVTextSubsector = "TVTextSubsectorError"; } int FirstSpace = TVTextSubsector.IndexOf(" "); string subject = $"{ TVTextSubsector.Substring(0, (FirstSpace > 0 ? FirstSpace : TVTextSubsector.Length)) } – Lab sheet received – High MPN / Feuille de laboratoire reçu - NPP élevé"; DateTime RunDate = new DateTime(int.Parse(labSheetAndA1Sheet.LabSheetA1Sheet.RunYear), int.Parse(labSheetAndA1Sheet.LabSheetA1Sheet.RunMonth), int.Parse(labSheetAndA1Sheet.LabSheetA1Sheet.RunDay)); StringBuilder msg = new StringBuilder(); // ---------------------- English part -------------- msg.AppendLine(@"<p>(français suit)</p>"); msg.AppendLine(@"<h2>Lab Sheet received</h2>"); msg.AppendLine($@"<h4>Subsector: { TVTextSubsector }</h4>"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA"); msg.AppendLine($@"<h4>Run Date: { RunDate.ToString("MMMM dd, yyyy") }</h4>"); if (!IsContractor) { msg.AppendLine($@"<a href=""{ href }"">Open CSSPWebTools</a>"); } msg.AppendLine(@"<br /><br />"); msg.AppendLine(@"<p><b>Note: </b> Sites below are over the MPN threshold of 500</p>"); List <LabSheetA1Measurement> labSheetA1MeasurementList = (from c in labSheetAndA1Sheet.LabSheetA1Sheet.LabSheetA1MeasurementList where c.MPN != null && c.MPN >= MPNLimitForEmail select c).ToList(); msg.AppendLine("<ol>"); foreach (LabSheetA1Measurement labSheetA1Measurment in labSheetA1MeasurementList) { msg.AppendLine("<li>"); msg.AppendLine($"<b>Site: </b>{ labSheetA1Measurment.Site }{ (labSheetA1Measurment.SampleType == SampleTypeEnum.DailyDuplicate ? " Daily duplicate" : "") } <b>MPN: </b>{ labSheetA1Measurment.MPN }"); msg.AppendLine("</li>"); } msg.AppendLine("</ol>"); msg.AppendLine(@"<br>"); msg.AppendLine(@"<p>Auto email from CSSPWebTools</p>"); msg.AppendLine(@"<br>"); msg.AppendLine(@"<hr />"); // ---------------------- French part -------------- msg.AppendLine(@"<hr />"); msg.AppendLine(@"<br>"); msg.AppendLine(@"<h2>Feuille de laboratoire reçu</h2>"); msg.AppendLine($@"<h4>Sous-secteur: { TVTextSubsector }</h4>"); Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA"); msg.AppendLine($@"<h4>Date de la tournée: { RunDate.ToString("dd MMMM, yyyy") }</h4>"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA"); if (!IsContractor) { msg.AppendLine($@"<a href=""{ href.Replace("en-CA", "fr-CA") }"">Open CSSPWebTools</a>"); } msg.AppendLine(@"<br /><br />"); msg.AppendLine(@"<p><b>Remarque: </b> Les sites ci-dessous ont une valeure de NPP dépassant 500</p>"); msg.AppendLine("<ol>"); foreach (LabSheetA1Measurement labSheetA1Measurment in labSheetA1MeasurementList) { msg.AppendLine("<li>"); msg.AppendLine($"<b>Site: </b>{ labSheetA1Measurment.Site }{ (labSheetA1Measurment.SampleType == SampleTypeEnum.DailyDuplicate ? " Duplicata journalier" : "") } <b>NPP: </b>{ labSheetA1Measurment.MPN }"); msg.AppendLine("</li>"); } msg.AppendLine("</ol>"); msg.AppendLine(@"<br>"); msg.AppendLine(@"<p>Courriel automatique provenant de CSSPWebTools</p>"); mail.Subject = subject; mail.Body = msg.ToString(); myClient.Send(mail); } } }
public void SendNewLabSheetEmail(string href, TVItem tvItemProvince, TVItem tvItemSubsector, LabSheetAndA1Sheet labSheetAndA1Sheet) { using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerCSSPDB)) { SamplingPlan samplingPlan = (from c in db.SamplingPlans where c.SamplingPlanID == labSheetAndA1Sheet.LabSheet.SamplingPlanID select c).FirstOrDefault(); List <SamplingPlanEmail> SamplingPlanEmailList = (from c in db.SamplingPlanEmails where c.SamplingPlanID == samplingPlan.SamplingPlanID orderby c.Email select c).ToList(); if (!samplingPlan.IsActive) { return; } // sending email to Non Contractors foreach (bool IsContractor in new List <bool> { false, true }) { MailMessage mail = new MailMessage(); foreach (SamplingPlanEmail samplingPlanEmail in SamplingPlanEmailList.Where(c => c.IsContractor == IsContractor && c.LabSheetReceived == true)) { mail.To.Add(samplingPlanEmail.Email.ToLower()); } if (mail.To.Count == 0) { continue; } mail.From = new MailAddress("*****@*****.**"); mail.IsBodyHtml = true; SmtpClient myClient = new System.Net.Mail.SmtpClient(); myClient.Host = "smtp.email-courriel.canada.ca"; myClient.Port = 587; myClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "H^9h6g@Gy$N57k=Dr@J7=F2y6p6b!T"); myClient.EnableSsl = true; string TVTextSubsector = (from c in db.TVItemLanguages where c.TVItemID == tvItemSubsector.TVItemID && c.Language == LanguageEnum.en select c.TVText).FirstOrDefault(); if (string.IsNullOrWhiteSpace(TVTextSubsector)) { TVTextSubsector = "TVTextSubsectorError"; } int FirstSpace = TVTextSubsector.IndexOf(" "); string subject = $"{ TVTextSubsector.Substring(0, (FirstSpace > 0 ? FirstSpace : TVTextSubsector.Length)) } – Lab sheet received / Feuille de laboratoire reçu"; DateTime RunDate = new DateTime(int.Parse(labSheetAndA1Sheet.LabSheetA1Sheet.RunYear), int.Parse(labSheetAndA1Sheet.LabSheetA1Sheet.RunMonth), int.Parse(labSheetAndA1Sheet.LabSheetA1Sheet.RunDay)); StringBuilder msg = new StringBuilder(); // ---------------------- English part -------------- msg.AppendLine(@"<p>(français suit)</p>"); msg.AppendLine(@"<h2>Lab Sheet received</h2>"); msg.AppendLine($@"<h4>Subsector: { TVTextSubsector }</h4>"); msg.AppendLine($@"<h4>Run Date: { RunDate.ToString("MMMM dd, yyyy") }</h4>"); if (!IsContractor) { msg.AppendLine($@"<a href=""{ href }"">Open CSSPWebTools</a>"); } msg.AppendLine(@"<br>"); msg.AppendLine(@"<p>Auto email from CSSPWebTools</p>"); msg.AppendLine(@"<br>"); msg.AppendLine(@"<hr />"); // ---------------------- French part -------------- msg.AppendLine(@"<hr />"); msg.AppendLine(@"<br>"); msg.AppendLine(@"<h2>Feuille de laboratoire reçu</h2>"); msg.AppendLine($@"<h4>Sous-secteur: { TVTextSubsector }</h4>"); Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA"); msg.AppendLine($@"<h4>Date de la tournée: { RunDate.ToString("dd MMMM, yyyy") }</h4>"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA"); if (!IsContractor) { msg.AppendLine($@"<a href=""{ href.Replace("en-CA", "fr-CA") }"">Open CSSPWebTools</a>"); } msg.AppendLine(@"<br>"); msg.AppendLine(@"<p>Courriel automatique provenant de CSSPWebTools</p>"); mail.Subject = subject; mail.Body = msg.ToString(); myClient.Send(mail); } } }
public void SamplingPlan_Controller_GetSamplingPlanList_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { SamplingPlanController samplingPlanController = new SamplingPlanController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(samplingPlanController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanController.DatabaseType); SamplingPlan samplingPlanFirst = new SamplingPlan(); int count = -1; Query query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { SamplingPlanService samplingPlanService = new SamplingPlanService(query, db, ContactID); samplingPlanFirst = (from c in db.SamplingPlans select c).FirstOrDefault(); count = (from c in db.SamplingPlans select c).Count(); count = (query.Take > count ? count : query.Take); } // ok with SamplingPlan info IHttpActionResult jsonRet = samplingPlanController.GetSamplingPlanList(); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <List <SamplingPlan> > ret = jsonRet as OkNegotiatedContentResult <List <SamplingPlan> >; Assert.AreEqual(samplingPlanFirst.SamplingPlanID, ret.Content[0].SamplingPlanID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); List <SamplingPlan> samplingPlanList = new List <SamplingPlan>(); count = -1; query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { SamplingPlanService samplingPlanService = new SamplingPlanService(query, db, ContactID); samplingPlanList = (from c in db.SamplingPlans select c).OrderBy(c => c.SamplingPlanID).Skip(0).Take(2).ToList(); count = (from c in db.SamplingPlans select c).Count(); } if (count > 0) { query.Skip = 0; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with SamplingPlan info jsonRet = samplingPlanController.GetSamplingPlanList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet); ret = jsonRet as OkNegotiatedContentResult <List <SamplingPlan> >; Assert.AreEqual(samplingPlanList[0].SamplingPlanID, ret.Content[0].SamplingPlanID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); if (count > 1) { query.Skip = 1; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with SamplingPlan info IHttpActionResult jsonRet2 = samplingPlanController.GetSamplingPlanList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <List <SamplingPlan> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <SamplingPlan> >; Assert.AreEqual(samplingPlanList[1].SamplingPlanID, ret2.Content[0].SamplingPlanID); Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count); } } } } }
public void SamplingPlan_Controller_Delete_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { SamplingPlanController samplingPlanController = new SamplingPlanController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(samplingPlanController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanController.DatabaseType); SamplingPlan samplingPlanLast = new SamplingPlan(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; SamplingPlanService samplingPlanService = new SamplingPlanService(query, db, ContactID); samplingPlanLast = (from c in db.SamplingPlans select c).FirstOrDefault(); } // ok with SamplingPlan info IHttpActionResult jsonRet = samplingPlanController.GetSamplingPlanWithID(samplingPlanLast.SamplingPlanID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <SamplingPlan> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlan>; SamplingPlan samplingPlanRet = Ret.Content; Assert.AreEqual(samplingPlanLast.SamplingPlanID, samplingPlanRet.SamplingPlanID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return newly added SamplingPlan samplingPlanRet.SamplingPlanID = 0; samplingPlanRet.SamplingPlanName = samplingPlanRet.SamplingPlanName.Replace(".txt", "_a.txt"); samplingPlanController.Request = new System.Net.Http.HttpRequestMessage(); samplingPlanController.Request.RequestUri = new System.Uri("http://localhost:5000/api/samplingPlan"); IHttpActionResult jsonRet3 = samplingPlanController.Post(samplingPlanRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <SamplingPlan> samplingPlanRet3 = jsonRet3 as CreatedNegotiatedContentResult <SamplingPlan>; Assert.IsNotNull(samplingPlanRet3); SamplingPlan samplingPlan = samplingPlanRet3.Content; BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); // Delete to return success IHttpActionResult jsonRet2 = samplingPlanController.Delete(samplingPlanRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <SamplingPlan> samplingPlanRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlan>; Assert.IsNotNull(samplingPlanRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Delete to return CSSPError because SamplingPlanID of 0 does not exist samplingPlanRet.SamplingPlanID = 0; IHttpActionResult jsonRet4 = samplingPlanController.Delete(samplingPlanRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <SamplingPlan> samplingPlanRet4 = jsonRet4 as OkNegotiatedContentResult <SamplingPlan>; Assert.IsNull(samplingPlanRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest4); } } }
private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); SamplingPlanEmail samplingPlanEmail = validationContext.ObjectInstance as SamplingPlanEmail; samplingPlanEmail.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (samplingPlanEmail.SamplingPlanEmailID == 0) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanEmailID"), new[] { "SamplingPlanEmailID" })); } if (!(from c in db.SamplingPlanEmails select c).Where(c => c.SamplingPlanEmailID == samplingPlanEmail.SamplingPlanEmailID).Any()) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlanEmail", "SamplingPlanEmailID", samplingPlanEmail.SamplingPlanEmailID.ToString()), new[] { "SamplingPlanEmailID" })); } } SamplingPlan SamplingPlanSamplingPlanID = (from c in db.SamplingPlans where c.SamplingPlanID == samplingPlanEmail.SamplingPlanID select c).FirstOrDefault(); if (SamplingPlanSamplingPlanID == null) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", samplingPlanEmail.SamplingPlanID.ToString()), new[] { "SamplingPlanID" })); } if (string.IsNullOrWhiteSpace(samplingPlanEmail.Email)) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Email"), new[] { "Email" })); } if (!string.IsNullOrWhiteSpace(samplingPlanEmail.Email) && samplingPlanEmail.Email.Length > 150) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Email", "150"), new[] { "Email" })); } if (!string.IsNullOrWhiteSpace(samplingPlanEmail.Email)) { Regex regex = new Regex(@"^([\w\!\#$\%\&\'*\+\-\/\=\?\^`{\|\}\~]+\.)*[\w\!\#$\%\&\'*\+\-\/\=\?\^`{\|\}\~]+@((((([a-zA-Z0-9]{1}[a-zA-Z0-9\-]{0,62}[a-zA-Z0-9]{1})|[a-zA-Z])\.)+[a-zA-Z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$"); if (!regex.IsMatch(samplingPlanEmail.Email)) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotAValidEmail, "Email"), new[] { "Email" })); } } if (samplingPlanEmail.LastUpdateDate_UTC.Year == 1) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (samplingPlanEmail.LastUpdateDate_UTC.Year < 1980) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlanEmail.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", samplingPlanEmail.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { samplingPlanEmail.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); LabSheetDetail labSheetDetail = validationContext.ObjectInstance as LabSheetDetail; labSheetDetail.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (labSheetDetail.LabSheetDetailID == 0) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetDetailID"), new[] { "LabSheetDetailID" })); } if (!(from c in db.LabSheetDetails select c).Where(c => c.LabSheetDetailID == labSheetDetail.LabSheetDetailID).Any()) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "LabSheetDetail", "LabSheetDetailID", labSheetDetail.LabSheetDetailID.ToString()), new[] { "LabSheetDetailID" })); } } LabSheet LabSheetLabSheetID = (from c in db.LabSheets where c.LabSheetID == labSheetDetail.LabSheetID select c).FirstOrDefault(); if (LabSheetLabSheetID == null) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "LabSheet", "LabSheetID", labSheetDetail.LabSheetID.ToString()), new[] { "LabSheetID" })); } SamplingPlan SamplingPlanSamplingPlanID = (from c in db.SamplingPlans where c.SamplingPlanID == labSheetDetail.SamplingPlanID select c).FirstOrDefault(); if (SamplingPlanSamplingPlanID == null) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", labSheetDetail.SamplingPlanID.ToString()), new[] { "SamplingPlanID" })); } TVItem TVItemSubsectorTVItemID = (from c in db.TVItems where c.TVItemID == labSheetDetail.SubsectorTVItemID select c).FirstOrDefault(); if (TVItemSubsectorTVItemID == null) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SubsectorTVItemID", labSheetDetail.SubsectorTVItemID.ToString()), new[] { "SubsectorTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Subsector, }; if (!AllowableTVTypes.Contains(TVItemSubsectorTVItemID.TVType)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "SubsectorTVItemID", "Subsector"), new[] { "SubsectorTVItemID" })); } } if (labSheetDetail.Version < 1 || labSheetDetail.Version > 5) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Version", "1", "5"), new[] { "Version" })); } if (labSheetDetail.RunDate.Year == 1) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "RunDate"), new[] { "RunDate" })); } else { if (labSheetDetail.RunDate.Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "RunDate", "1980"), new[] { "RunDate" })); } } if (string.IsNullOrWhiteSpace(labSheetDetail.Tides)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Tides"), new[] { "Tides" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Tides) && (labSheetDetail.Tides.Length < 1 || labSheetDetail.Tides.Length > 7)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Tides", "1", "7"), new[] { "Tides" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.SampleCrewInitials) && labSheetDetail.SampleCrewInitials.Length > 20) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SampleCrewInitials", "20"), new[] { "SampleCrewInitials" })); } if (labSheetDetail.WaterBathCount != null) { if (labSheetDetail.WaterBathCount < 1 || labSheetDetail.WaterBathCount > 3) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "WaterBathCount", "1", "3"), new[] { "WaterBathCount" })); } } if (labSheetDetail.IncubationBath1StartTime != null && ((DateTime)labSheetDetail.IncubationBath1StartTime).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath1StartTime", "1980"), new[] { "IncubationBath1StartTime" })); } if (labSheetDetail.IncubationBath2StartTime != null && ((DateTime)labSheetDetail.IncubationBath2StartTime).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath2StartTime", "1980"), new[] { "IncubationBath2StartTime" })); } if (labSheetDetail.IncubationBath3StartTime != null && ((DateTime)labSheetDetail.IncubationBath3StartTime).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath3StartTime", "1980"), new[] { "IncubationBath3StartTime" })); } if (labSheetDetail.IncubationBath1EndTime != null && ((DateTime)labSheetDetail.IncubationBath1EndTime).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath1EndTime", "1980"), new[] { "IncubationBath1EndTime" })); } if (labSheetDetail.IncubationBath2EndTime != null && ((DateTime)labSheetDetail.IncubationBath2EndTime).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath2EndTime", "1980"), new[] { "IncubationBath2EndTime" })); } if (labSheetDetail.IncubationBath3EndTime != null && ((DateTime)labSheetDetail.IncubationBath3EndTime).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath3EndTime", "1980"), new[] { "IncubationBath3EndTime" })); } if (labSheetDetail.IncubationBath1TimeCalculated_minutes != null) { if (labSheetDetail.IncubationBath1TimeCalculated_minutes < 0 || labSheetDetail.IncubationBath1TimeCalculated_minutes > 10000) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IncubationBath1TimeCalculated_minutes", "0", "10000"), new[] { "IncubationBath1TimeCalculated_minutes" })); } } if (labSheetDetail.IncubationBath2TimeCalculated_minutes != null) { if (labSheetDetail.IncubationBath2TimeCalculated_minutes < 0 || labSheetDetail.IncubationBath2TimeCalculated_minutes > 10000) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IncubationBath2TimeCalculated_minutes", "0", "10000"), new[] { "IncubationBath2TimeCalculated_minutes" })); } } if (labSheetDetail.IncubationBath3TimeCalculated_minutes != null) { if (labSheetDetail.IncubationBath3TimeCalculated_minutes < 0 || labSheetDetail.IncubationBath3TimeCalculated_minutes > 10000) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IncubationBath3TimeCalculated_minutes", "0", "10000"), new[] { "IncubationBath3TimeCalculated_minutes" })); } } if (!string.IsNullOrWhiteSpace(labSheetDetail.WaterBath1) && labSheetDetail.WaterBath1.Length > 10) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "WaterBath1", "10"), new[] { "WaterBath1" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.WaterBath2) && labSheetDetail.WaterBath2.Length > 10) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "WaterBath2", "10"), new[] { "WaterBath2" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.WaterBath3) && labSheetDetail.WaterBath3.Length > 10) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "WaterBath3", "10"), new[] { "WaterBath3" })); } if (labSheetDetail.TCField1 != null) { if (labSheetDetail.TCField1 < -10 || labSheetDetail.TCField1 > 40) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCField1", "-10", "40"), new[] { "TCField1" })); } } if (labSheetDetail.TCLab1 != null) { if (labSheetDetail.TCLab1 < -10 || labSheetDetail.TCLab1 > 40) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCLab1", "-10", "40"), new[] { "TCLab1" })); } } if (labSheetDetail.TCField2 != null) { if (labSheetDetail.TCField2 < -10 || labSheetDetail.TCField2 > 40) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCField2", "-10", "40"), new[] { "TCField2" })); } } if (labSheetDetail.TCLab2 != null) { if (labSheetDetail.TCLab2 < -10 || labSheetDetail.TCLab2 > 40) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCLab2", "-10", "40"), new[] { "TCLab2" })); } } if (labSheetDetail.TCFirst != null) { if (labSheetDetail.TCFirst < -10 || labSheetDetail.TCFirst > 40) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCFirst", "-10", "40"), new[] { "TCFirst" })); } } if (labSheetDetail.TCAverage != null) { if (labSheetDetail.TCAverage < -10 || labSheetDetail.TCAverage > 40) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCAverage", "-10", "40"), new[] { "TCAverage" })); } } if (!string.IsNullOrWhiteSpace(labSheetDetail.ControlLot) && labSheetDetail.ControlLot.Length > 100) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ControlLot", "100"), new[] { "ControlLot" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Positive35) && (labSheetDetail.Positive35.Length < 1 || labSheetDetail.Positive35.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Positive35", "1", "1"), new[] { "Positive35" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.NonTarget35) && (labSheetDetail.NonTarget35.Length < 1 || labSheetDetail.NonTarget35.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "NonTarget35", "1", "1"), new[] { "NonTarget35" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Negative35) && (labSheetDetail.Negative35.Length < 1 || labSheetDetail.Negative35.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Negative35", "1", "1"), new[] { "Negative35" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath1Positive44_5) && (labSheetDetail.Bath1Positive44_5.Length < 1 || labSheetDetail.Bath1Positive44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath1Positive44_5", "1", "1"), new[] { "Bath1Positive44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath2Positive44_5) && (labSheetDetail.Bath2Positive44_5.Length < 1 || labSheetDetail.Bath2Positive44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath2Positive44_5", "1", "1"), new[] { "Bath2Positive44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath3Positive44_5) && (labSheetDetail.Bath3Positive44_5.Length < 1 || labSheetDetail.Bath3Positive44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath3Positive44_5", "1", "1"), new[] { "Bath3Positive44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath1NonTarget44_5) && (labSheetDetail.Bath1NonTarget44_5.Length < 1 || labSheetDetail.Bath1NonTarget44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath1NonTarget44_5", "1", "1"), new[] { "Bath1NonTarget44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath2NonTarget44_5) && (labSheetDetail.Bath2NonTarget44_5.Length < 1 || labSheetDetail.Bath2NonTarget44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath2NonTarget44_5", "1", "1"), new[] { "Bath2NonTarget44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath3NonTarget44_5) && (labSheetDetail.Bath3NonTarget44_5.Length < 1 || labSheetDetail.Bath3NonTarget44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath3NonTarget44_5", "1", "1"), new[] { "Bath3NonTarget44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath1Negative44_5) && (labSheetDetail.Bath1Negative44_5.Length < 1 || labSheetDetail.Bath1Negative44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath1Negative44_5", "1", "1"), new[] { "Bath1Negative44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath2Negative44_5) && (labSheetDetail.Bath2Negative44_5.Length < 1 || labSheetDetail.Bath2Negative44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath2Negative44_5", "1", "1"), new[] { "Bath2Negative44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath3Negative44_5) && (labSheetDetail.Bath3Negative44_5.Length < 1 || labSheetDetail.Bath3Negative44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath3Negative44_5", "1", "1"), new[] { "Bath3Negative44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Blank35) && (labSheetDetail.Blank35.Length < 1 || labSheetDetail.Blank35.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Blank35", "1", "1"), new[] { "Blank35" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath1Blank44_5) && (labSheetDetail.Bath1Blank44_5.Length < 1 || labSheetDetail.Bath1Blank44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath1Blank44_5", "1", "1"), new[] { "Bath1Blank44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath2Blank44_5) && (labSheetDetail.Bath2Blank44_5.Length < 1 || labSheetDetail.Bath2Blank44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath2Blank44_5", "1", "1"), new[] { "Bath2Blank44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath3Blank44_5) && (labSheetDetail.Bath3Blank44_5.Length < 1 || labSheetDetail.Bath3Blank44_5.Length > 1)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath3Blank44_5", "1", "1"), new[] { "Bath3Blank44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Lot35) && labSheetDetail.Lot35.Length > 20) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Lot35", "20"), new[] { "Lot35" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Lot44_5) && labSheetDetail.Lot44_5.Length > 20) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Lot44_5", "20"), new[] { "Lot44_5" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.Weather) && labSheetDetail.Weather.Length > 250) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Weather", "250"), new[] { "Weather" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.RunComment) && labSheetDetail.RunComment.Length > 250) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "RunComment", "250"), new[] { "RunComment" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.RunWeatherComment) && labSheetDetail.RunWeatherComment.Length > 250) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "RunWeatherComment", "250"), new[] { "RunWeatherComment" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.SampleBottleLotNumber) && labSheetDetail.SampleBottleLotNumber.Length > 20) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SampleBottleLotNumber", "20"), new[] { "SampleBottleLotNumber" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.SalinitiesReadBy) && labSheetDetail.SalinitiesReadBy.Length > 20) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SalinitiesReadBy", "20"), new[] { "SalinitiesReadBy" })); } if (labSheetDetail.SalinitiesReadDate != null && ((DateTime)labSheetDetail.SalinitiesReadDate).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "SalinitiesReadDate", "1980"), new[] { "SalinitiesReadDate" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.ResultsReadBy) && labSheetDetail.ResultsReadBy.Length > 20) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ResultsReadBy", "20"), new[] { "ResultsReadBy" })); } if (labSheetDetail.ResultsReadDate != null && ((DateTime)labSheetDetail.ResultsReadDate).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "ResultsReadDate", "1980"), new[] { "ResultsReadDate" })); } if (!string.IsNullOrWhiteSpace(labSheetDetail.ResultsRecordedBy) && labSheetDetail.ResultsRecordedBy.Length > 20) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ResultsRecordedBy", "20"), new[] { "ResultsRecordedBy" })); } if (labSheetDetail.ResultsRecordedDate != null && ((DateTime)labSheetDetail.ResultsRecordedDate).Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "ResultsRecordedDate", "1980"), new[] { "ResultsRecordedDate" })); } if (labSheetDetail.DailyDuplicateRLog != null) { if (labSheetDetail.DailyDuplicateRLog < 0 || labSheetDetail.DailyDuplicateRLog > 100) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DailyDuplicateRLog", "0", "100"), new[] { "DailyDuplicateRLog" })); } } if (labSheetDetail.DailyDuplicatePrecisionCriteria != null) { if (labSheetDetail.DailyDuplicatePrecisionCriteria < 0 || labSheetDetail.DailyDuplicatePrecisionCriteria > 100) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DailyDuplicatePrecisionCriteria", "0", "100"), new[] { "DailyDuplicatePrecisionCriteria" })); } } if (labSheetDetail.IntertechDuplicateRLog != null) { if (labSheetDetail.IntertechDuplicateRLog < 0 || labSheetDetail.IntertechDuplicateRLog > 100) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IntertechDuplicateRLog", "0", "100"), new[] { "IntertechDuplicateRLog" })); } } if (labSheetDetail.IntertechDuplicatePrecisionCriteria != null) { if (labSheetDetail.IntertechDuplicatePrecisionCriteria < 0 || labSheetDetail.IntertechDuplicatePrecisionCriteria > 100) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IntertechDuplicatePrecisionCriteria", "0", "100"), new[] { "IntertechDuplicatePrecisionCriteria" })); } } if (labSheetDetail.LastUpdateDate_UTC.Year == 1) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (labSheetDetail.LastUpdateDate_UTC.Year < 1980) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == labSheetDetail.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", labSheetDetail.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { labSheetDetail.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { labSheetDetail.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
/// <summary> /// Validate function for all LabSheetService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); LabSheet labSheet = validationContext.ObjectInstance as LabSheet; labSheet.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (labSheet.LabSheetID == 0) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetID"), new[] { "LabSheetID" })); } if (!(from c in db.LabSheets select c).Where(c => c.LabSheetID == labSheet.LabSheetID).Any()) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "LabSheet", "LabSheetID", labSheet.LabSheetID.ToString()), new[] { "LabSheetID" })); } } if (labSheet.OtherServerLabSheetID < 1) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MinValueIs_, "OtherServerLabSheetID", "1"), new[] { "OtherServerLabSheetID" })); } SamplingPlan SamplingPlanSamplingPlanID = (from c in db.SamplingPlans where c.SamplingPlanID == labSheet.SamplingPlanID select c).FirstOrDefault(); if (SamplingPlanSamplingPlanID == null) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", labSheet.SamplingPlanID.ToString()), new[] { "SamplingPlanID" })); } if (string.IsNullOrWhiteSpace(labSheet.SamplingPlanName)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanName"), new[] { "SamplingPlanName" })); } if (!string.IsNullOrWhiteSpace(labSheet.SamplingPlanName) && (labSheet.SamplingPlanName.Length < 1 || labSheet.SamplingPlanName.Length > 250)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "SamplingPlanName", "1", "250"), new[] { "SamplingPlanName" })); } if (labSheet.Year < 1980) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MinValueIs_, "Year", "1980"), new[] { "Year" })); } if (labSheet.Month < 1 || labSheet.Month > 12) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Month", "1", "12"), new[] { "Month" })); } if (labSheet.Day < 1 || labSheet.Day > 31) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Day", "1", "31"), new[] { "Day" })); } if (labSheet.RunNumber < 1 || labSheet.RunNumber > 100) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "RunNumber", "1", "100"), new[] { "RunNumber" })); } TVItem TVItemSubsectorTVItemID = (from c in db.TVItems where c.TVItemID == labSheet.SubsectorTVItemID select c).FirstOrDefault(); if (TVItemSubsectorTVItemID == null) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SubsectorTVItemID", labSheet.SubsectorTVItemID.ToString()), new[] { "SubsectorTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Subsector, }; if (!AllowableTVTypes.Contains(TVItemSubsectorTVItemID.TVType)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "SubsectorTVItemID", "Subsector"), new[] { "SubsectorTVItemID" })); } } if (labSheet.MWQMRunTVItemID != null) { TVItem TVItemMWQMRunTVItemID = (from c in db.TVItems where c.TVItemID == labSheet.MWQMRunTVItemID select c).FirstOrDefault(); if (TVItemMWQMRunTVItemID == null) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MWQMRunTVItemID", (labSheet.MWQMRunTVItemID == null ? "" : labSheet.MWQMRunTVItemID.ToString())), new[] { "MWQMRunTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.MWQMRun, }; if (!AllowableTVTypes.Contains(TVItemMWQMRunTVItemID.TVType)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "MWQMRunTVItemID", "MWQMRun"), new[] { "MWQMRunTVItemID" })); } } } retStr = enums.EnumTypeOK(typeof(SamplingPlanTypeEnum), (int?)labSheet.SamplingPlanType); if (!string.IsNullOrWhiteSpace(retStr)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanType"), new[] { "SamplingPlanType" })); } retStr = enums.EnumTypeOK(typeof(SampleTypeEnum), (int?)labSheet.SampleType); if (!string.IsNullOrWhiteSpace(retStr)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SampleType"), new[] { "SampleType" })); } retStr = enums.EnumTypeOK(typeof(LabSheetTypeEnum), (int?)labSheet.LabSheetType); if (!string.IsNullOrWhiteSpace(retStr)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetType"), new[] { "LabSheetType" })); } retStr = enums.EnumTypeOK(typeof(LabSheetStatusEnum), (int?)labSheet.LabSheetStatus); if (!string.IsNullOrWhiteSpace(retStr)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetStatus"), new[] { "LabSheetStatus" })); } if (string.IsNullOrWhiteSpace(labSheet.FileName)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "FileName"), new[] { "FileName" })); } if (!string.IsNullOrWhiteSpace(labSheet.FileName) && (labSheet.FileName.Length < 1 || labSheet.FileName.Length > 250)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "FileName", "1", "250"), new[] { "FileName" })); } if (labSheet.FileLastModifiedDate_Local.Year == 1) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "FileLastModifiedDate_Local"), new[] { "FileLastModifiedDate_Local" })); } else { if (labSheet.FileLastModifiedDate_Local.Year < 1980) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "FileLastModifiedDate_Local", "1980"), new[] { "FileLastModifiedDate_Local" })); } } if (string.IsNullOrWhiteSpace(labSheet.FileContent)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "FileContent"), new[] { "FileContent" })); } //FileContent has no StringLength Attribute if (labSheet.AcceptedOrRejectedByContactTVItemID != null) { TVItem TVItemAcceptedOrRejectedByContactTVItemID = (from c in db.TVItems where c.TVItemID == labSheet.AcceptedOrRejectedByContactTVItemID select c).FirstOrDefault(); if (TVItemAcceptedOrRejectedByContactTVItemID == null) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "AcceptedOrRejectedByContactTVItemID", (labSheet.AcceptedOrRejectedByContactTVItemID == null ? "" : labSheet.AcceptedOrRejectedByContactTVItemID.ToString())), new[] { "AcceptedOrRejectedByContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemAcceptedOrRejectedByContactTVItemID.TVType)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "AcceptedOrRejectedByContactTVItemID", "Contact"), new[] { "AcceptedOrRejectedByContactTVItemID" })); } } } if (labSheet.AcceptedOrRejectedDateTime != null && ((DateTime)labSheet.AcceptedOrRejectedDateTime).Year < 1980) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "AcceptedOrRejectedDateTime", "1980"), new[] { "AcceptedOrRejectedDateTime" })); } if (!string.IsNullOrWhiteSpace(labSheet.RejectReason) && labSheet.RejectReason.Length > 250) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "RejectReason", "250"), new[] { "RejectReason" })); } if (labSheet.LastUpdateDate_UTC.Year == 1) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (labSheet.LastUpdateDate_UTC.Year < 1980) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == labSheet.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", labSheet.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { labSheet.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { labSheet.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); SamplingPlan samplingPlan = validationContext.ObjectInstance as SamplingPlan; samplingPlan.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (samplingPlan.SamplingPlanID == 0) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanID"), new[] { "SamplingPlanID" })); } if (!(from c in db.SamplingPlans select c).Where(c => c.SamplingPlanID == samplingPlan.SamplingPlanID).Any()) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", samplingPlan.SamplingPlanID.ToString()), new[] { "SamplingPlanID" })); } } if (string.IsNullOrWhiteSpace(samplingPlan.SamplingPlanName)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanName"), new[] { "SamplingPlanName" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.SamplingPlanName) && samplingPlan.SamplingPlanName.Length > 200) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SamplingPlanName", "200"), new[] { "SamplingPlanName" })); } if (string.IsNullOrWhiteSpace(samplingPlan.ForGroupName)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ForGroupName"), new[] { "ForGroupName" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.ForGroupName) && samplingPlan.ForGroupName.Length > 100) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ForGroupName", "100"), new[] { "ForGroupName" })); } retStr = enums.EnumTypeOK(typeof(SampleTypeEnum), (int?)samplingPlan.SampleType); if (!string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SampleType"), new[] { "SampleType" })); } retStr = enums.EnumTypeOK(typeof(SamplingPlanTypeEnum), (int?)samplingPlan.SamplingPlanType); if (!string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanType"), new[] { "SamplingPlanType" })); } retStr = enums.EnumTypeOK(typeof(LabSheetTypeEnum), (int?)samplingPlan.LabSheetType); if (!string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetType"), new[] { "LabSheetType" })); } TVItem TVItemProvinceTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlan.ProvinceTVItemID select c).FirstOrDefault(); if (TVItemProvinceTVItemID == null) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ProvinceTVItemID", samplingPlan.ProvinceTVItemID.ToString()), new[] { "ProvinceTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Province, }; if (!AllowableTVTypes.Contains(TVItemProvinceTVItemID.TVType)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "ProvinceTVItemID", "Province"), new[] { "ProvinceTVItemID" })); } } TVItem TVItemCreatorTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlan.CreatorTVItemID select c).FirstOrDefault(); if (TVItemCreatorTVItemID == null) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "CreatorTVItemID", samplingPlan.CreatorTVItemID.ToString()), new[] { "CreatorTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemCreatorTVItemID.TVType)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "CreatorTVItemID", "Contact"), new[] { "CreatorTVItemID" })); } } if (samplingPlan.Year < 2000 || samplingPlan.Year > 2050) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Year", "2000", "2050"), new[] { "Year" })); } if (string.IsNullOrWhiteSpace(samplingPlan.AccessCode)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "AccessCode"), new[] { "AccessCode" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.AccessCode) && samplingPlan.AccessCode.Length > 15) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "AccessCode", "15"), new[] { "AccessCode" })); } if (samplingPlan.DailyDuplicatePrecisionCriteria < 0 || samplingPlan.DailyDuplicatePrecisionCriteria > 100) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DailyDuplicatePrecisionCriteria", "0", "100"), new[] { "DailyDuplicatePrecisionCriteria" })); } if (samplingPlan.IntertechDuplicatePrecisionCriteria < 0 || samplingPlan.IntertechDuplicatePrecisionCriteria > 100) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IntertechDuplicatePrecisionCriteria", "0", "100"), new[] { "IntertechDuplicatePrecisionCriteria" })); } if (string.IsNullOrWhiteSpace(samplingPlan.ApprovalCode)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ApprovalCode"), new[] { "ApprovalCode" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.ApprovalCode) && samplingPlan.ApprovalCode.Length > 15) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ApprovalCode", "15"), new[] { "ApprovalCode" })); } if (samplingPlan.SamplingPlanFileTVItemID != null) { TVItem TVItemSamplingPlanFileTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlan.SamplingPlanFileTVItemID select c).FirstOrDefault(); if (TVItemSamplingPlanFileTVItemID == null) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SamplingPlanFileTVItemID", (samplingPlan.SamplingPlanFileTVItemID == null ? "" : samplingPlan.SamplingPlanFileTVItemID.ToString())), new[] { "SamplingPlanFileTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.File, }; if (!AllowableTVTypes.Contains(TVItemSamplingPlanFileTVItemID.TVType)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "SamplingPlanFileTVItemID", "File"), new[] { "SamplingPlanFileTVItemID" })); } } } if (samplingPlan.AnalyzeMethodDefault != null) { retStr = enums.EnumTypeOK(typeof(AnalyzeMethodEnum), (int?)samplingPlan.AnalyzeMethodDefault); if (samplingPlan.AnalyzeMethodDefault == null || !string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "AnalyzeMethodDefault"), new[] { "AnalyzeMethodDefault" })); } } if (samplingPlan.SampleMatrixDefault != null) { retStr = enums.EnumTypeOK(typeof(SampleMatrixEnum), (int?)samplingPlan.SampleMatrixDefault); if (samplingPlan.SampleMatrixDefault == null || !string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SampleMatrixDefault"), new[] { "SampleMatrixDefault" })); } } if (samplingPlan.LaboratoryDefault != null) { retStr = enums.EnumTypeOK(typeof(LaboratoryEnum), (int?)samplingPlan.LaboratoryDefault); if (samplingPlan.LaboratoryDefault == null || !string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LaboratoryDefault"), new[] { "LaboratoryDefault" })); } } if (string.IsNullOrWhiteSpace(samplingPlan.BackupDirectory)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "BackupDirectory"), new[] { "BackupDirectory" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.BackupDirectory) && samplingPlan.BackupDirectory.Length > 250) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "BackupDirectory", "250"), new[] { "BackupDirectory" })); } if (samplingPlan.LastUpdateDate_UTC.Year == 1) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (samplingPlan.LastUpdateDate_UTC.Year < 1980) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlan.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", samplingPlan.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { samplingPlan.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
public SamplingPlanTest() { samplingPlan = new SamplingPlan(); samplingPlanExtraA = new SamplingPlanExtraA(); samplingPlanExtraB = new SamplingPlanExtraB(); }
private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); SamplingPlanSubsector samplingPlanSubsector = validationContext.ObjectInstance as SamplingPlanSubsector; samplingPlanSubsector.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (samplingPlanSubsector.SamplingPlanSubsectorID == 0) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanSubsectorID"), new[] { "SamplingPlanSubsectorID" })); } if (!(from c in db.SamplingPlanSubsectors select c).Where(c => c.SamplingPlanSubsectorID == samplingPlanSubsector.SamplingPlanSubsectorID).Any()) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlanSubsector", "SamplingPlanSubsectorID", samplingPlanSubsector.SamplingPlanSubsectorID.ToString()), new[] { "SamplingPlanSubsectorID" })); } } SamplingPlan SamplingPlanSamplingPlanID = (from c in db.SamplingPlans where c.SamplingPlanID == samplingPlanSubsector.SamplingPlanID select c).FirstOrDefault(); if (SamplingPlanSamplingPlanID == null) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", samplingPlanSubsector.SamplingPlanID.ToString()), new[] { "SamplingPlanID" })); } TVItem TVItemSubsectorTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlanSubsector.SubsectorTVItemID select c).FirstOrDefault(); if (TVItemSubsectorTVItemID == null) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SubsectorTVItemID", samplingPlanSubsector.SubsectorTVItemID.ToString()), new[] { "SubsectorTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Subsector, }; if (!AllowableTVTypes.Contains(TVItemSubsectorTVItemID.TVType)) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "SubsectorTVItemID", "Subsector"), new[] { "SubsectorTVItemID" })); } } if (samplingPlanSubsector.LastUpdateDate_UTC.Year == 1) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (samplingPlanSubsector.LastUpdateDate_UTC.Year < 1980) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlanSubsector.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", samplingPlanSubsector.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { samplingPlanSubsector.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
/// <summary> /// 添加采样计划。 /// </summary> /// <param name="obj">采样计划数据。</param> /// <returns><see cref="MethodReturnResult" />.</returns> public MethodReturnResult Add(SamplingPlan obj) { return(base.Channel.Add(obj)); }
/// <summary> /// 修改采样计划。 /// </summary> /// <param name="obj">采样计划数据。</param> /// <returns><see cref="MethodReturnResult" />.</returns> public ServiceCenter.Model.MethodReturnResult Modify(SamplingPlan obj) { return(base.Channel.Modify(obj)); }