public void MWQMSiteStartEndDate_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); int count = 0; if (count == 1) { // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used] } MWQMSiteStartEndDate mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Count(); Assert.AreEqual(count, (from c in dbTestDB.MWQMSiteStartEndDates select c).Count()); mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); if (mwqmSiteStartEndDate.HasErrors) { Assert.AreEqual("", mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Where(c => c == mwqmSiteStartEndDate).Any()); mwqmSiteStartEndDateService.Update(mwqmSiteStartEndDate); if (mwqmSiteStartEndDate.HasErrors) { Assert.AreEqual("", mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Count()); mwqmSiteStartEndDateService.Delete(mwqmSiteStartEndDate); if (mwqmSiteStartEndDate.HasErrors) { Assert.AreEqual("", mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Count()); } } }
public IHttpActionResult Delete([FromBody] MWQMSiteStartEndDate mwqmSiteStartEndDate, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!mwqmSiteStartEndDateService.Delete(mwqmSiteStartEndDate)) { return(BadRequest(String.Join("|||", mwqmSiteStartEndDate.ValidationResults))); } else { mwqmSiteStartEndDate.ValidationResults = null; return(Ok(mwqmSiteStartEndDate)); } } }