public IHttpActionResult GetPolSourceSiteWithID([FromUri] int PolSourceSiteID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { PolSourceSiteService polSourceSiteService = new PolSourceSiteService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); polSourceSiteService.Query = polSourceSiteService.FillQuery(typeof(PolSourceSite), lang, 0, 1, "", "", extra); if (polSourceSiteService.Query.Extra == "A") { PolSourceSiteExtraA polSourceSiteExtraA = new PolSourceSiteExtraA(); polSourceSiteExtraA = polSourceSiteService.GetPolSourceSiteExtraAWithPolSourceSiteID(PolSourceSiteID); if (polSourceSiteExtraA == null) { return(NotFound()); } return(Ok(polSourceSiteExtraA)); } else if (polSourceSiteService.Query.Extra == "B") { PolSourceSiteExtraB polSourceSiteExtraB = new PolSourceSiteExtraB(); polSourceSiteExtraB = polSourceSiteService.GetPolSourceSiteExtraBWithPolSourceSiteID(PolSourceSiteID); if (polSourceSiteExtraB == null) { return(NotFound()); } return(Ok(polSourceSiteExtraB)); } else { PolSourceSite polSourceSite = new PolSourceSite(); polSourceSite = polSourceSiteService.GetPolSourceSiteWithPolSourceSiteID(PolSourceSiteID); if (polSourceSite == null) { return(NotFound()); } return(Ok(polSourceSite)); } } }
public void GetPolSourceSiteList_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" }) { PolSourceSiteService polSourceSiteService = new PolSourceSiteService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); polSourceSiteService.Query = polSourceSiteService.FillQuery(typeof(PolSourceSite), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "PolSourceSiteID,GT,2|PolSourceSiteID,LT,5", extra); List <PolSourceSite> polSourceSiteDirectQueryList = new List <PolSourceSite>(); polSourceSiteDirectQueryList = (from c in dbTestDB.PolSourceSites select c).Where(c => c.PolSourceSiteID > 2 && c.PolSourceSiteID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <PolSourceSite> polSourceSiteList = new List <PolSourceSite>(); polSourceSiteList = polSourceSiteService.GetPolSourceSiteList().ToList(); CheckPolSourceSiteFields(polSourceSiteList); Assert.AreEqual(polSourceSiteDirectQueryList[0].PolSourceSiteID, polSourceSiteList[0].PolSourceSiteID); } else { //Assert.AreEqual(true, false); } } } } }
public IHttpActionResult GetPolSourceSiteList([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)) { PolSourceSiteService polSourceSiteService = new PolSourceSiteService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { polSourceSiteService.Query = polSourceSiteService.FillQuery(typeof(PolSourceSiteExtraA), lang, skip, take, asc, desc, where, extra); if (polSourceSiteService.Query.HasErrors) { return(Ok(new List <PolSourceSiteExtraA>() { new PolSourceSiteExtraA() { HasErrors = polSourceSiteService.Query.HasErrors, ValidationResults = polSourceSiteService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(polSourceSiteService.GetPolSourceSiteExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { polSourceSiteService.Query = polSourceSiteService.FillQuery(typeof(PolSourceSiteExtraB), lang, skip, take, asc, desc, where, extra); if (polSourceSiteService.Query.HasErrors) { return(Ok(new List <PolSourceSiteExtraB>() { new PolSourceSiteExtraB() { HasErrors = polSourceSiteService.Query.HasErrors, ValidationResults = polSourceSiteService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(polSourceSiteService.GetPolSourceSiteExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { polSourceSiteService.Query = polSourceSiteService.FillQuery(typeof(PolSourceSite), lang, skip, take, asc, desc, where, extra); if (polSourceSiteService.Query.HasErrors) { return(Ok(new List <PolSourceSite>() { new PolSourceSite() { HasErrors = polSourceSiteService.Query.HasErrors, ValidationResults = polSourceSiteService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(polSourceSiteService.GetPolSourceSiteList().ToList())); } } } }