public IHttpActionResult GetMWQMSiteWithID([FromUri] int MWQMSiteID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMSiteService mwqmSiteService = new MWQMSiteService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); mwqmSiteService.Query = mwqmSiteService.FillQuery(typeof(MWQMSite), lang, 0, 1, "", "", extra); if (mwqmSiteService.Query.Extra == "A") { MWQMSiteExtraA mwqmSiteExtraA = new MWQMSiteExtraA(); mwqmSiteExtraA = mwqmSiteService.GetMWQMSiteExtraAWithMWQMSiteID(MWQMSiteID); if (mwqmSiteExtraA == null) { return(NotFound()); } return(Ok(mwqmSiteExtraA)); } else if (mwqmSiteService.Query.Extra == "B") { MWQMSiteExtraB mwqmSiteExtraB = new MWQMSiteExtraB(); mwqmSiteExtraB = mwqmSiteService.GetMWQMSiteExtraBWithMWQMSiteID(MWQMSiteID); if (mwqmSiteExtraB == null) { return(NotFound()); } return(Ok(mwqmSiteExtraB)); } else { MWQMSite mwqmSite = new MWQMSite(); mwqmSite = mwqmSiteService.GetMWQMSiteWithMWQMSiteID(MWQMSiteID); if (mwqmSite == null) { return(NotFound()); } return(Ok(mwqmSite)); } } }
public void GetMWQMSiteList_2Where_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { MWQMSiteService mwqmSiteService = new MWQMSiteService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); mwqmSiteService.Query = mwqmSiteService.FillQuery(typeof(MWQMSite), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "MWQMSiteID,GT,2|MWQMSiteID,LT,5", extra); List <MWQMSite> mwqmSiteDirectQueryList = new List <MWQMSite>(); mwqmSiteDirectQueryList = (from c in dbTestDB.MWQMSites select c).Where(c => c.MWQMSiteID > 2 && c.MWQMSiteID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <MWQMSite> mwqmSiteList = new List <MWQMSite>(); mwqmSiteList = mwqmSiteService.GetMWQMSiteList().ToList(); CheckMWQMSiteFields(mwqmSiteList); Assert.AreEqual(mwqmSiteDirectQueryList[0].MWQMSiteID, mwqmSiteList[0].MWQMSiteID); } else { //Assert.AreEqual(true, false); } } } } }
public IHttpActionResult GetMWQMSiteList([FromUri] string lang = "en", [FromUri] int skip = 0, [FromUri] int take = 200, [FromUri] string asc = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMSiteService mwqmSiteService = new MWQMSiteService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { mwqmSiteService.Query = mwqmSiteService.FillQuery(typeof(MWQMSiteExtraA), lang, skip, take, asc, desc, where, extra); if (mwqmSiteService.Query.HasErrors) { return(Ok(new List <MWQMSiteExtraA>() { new MWQMSiteExtraA() { HasErrors = mwqmSiteService.Query.HasErrors, ValidationResults = mwqmSiteService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmSiteService.GetMWQMSiteExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { mwqmSiteService.Query = mwqmSiteService.FillQuery(typeof(MWQMSiteExtraB), lang, skip, take, asc, desc, where, extra); if (mwqmSiteService.Query.HasErrors) { return(Ok(new List <MWQMSiteExtraB>() { new MWQMSiteExtraB() { HasErrors = mwqmSiteService.Query.HasErrors, ValidationResults = mwqmSiteService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmSiteService.GetMWQMSiteExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { mwqmSiteService.Query = mwqmSiteService.FillQuery(typeof(MWQMSite), lang, skip, take, asc, desc, where, extra); if (mwqmSiteService.Query.HasErrors) { return(Ok(new List <MWQMSite>() { new MWQMSite() { HasErrors = mwqmSiteService.Query.HasErrors, ValidationResults = mwqmSiteService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmSiteService.GetMWQMSiteList().ToList())); } } } }