public IHttpActionResult GetBoxModelLanguageWithID([FromUri] int BoxModelLanguageID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); boxModelLanguageService.Query = boxModelLanguageService.FillQuery(typeof(BoxModelLanguage), lang, 0, 1, "", "", extra); if (boxModelLanguageService.Query.Extra == "A") { BoxModelLanguageExtraA boxModelLanguageExtraA = new BoxModelLanguageExtraA(); boxModelLanguageExtraA = boxModelLanguageService.GetBoxModelLanguageExtraAWithBoxModelLanguageID(BoxModelLanguageID); if (boxModelLanguageExtraA == null) { return(NotFound()); } return(Ok(boxModelLanguageExtraA)); } else if (boxModelLanguageService.Query.Extra == "B") { BoxModelLanguageExtraB boxModelLanguageExtraB = new BoxModelLanguageExtraB(); boxModelLanguageExtraB = boxModelLanguageService.GetBoxModelLanguageExtraBWithBoxModelLanguageID(BoxModelLanguageID); if (boxModelLanguageExtraB == null) { return(NotFound()); } return(Ok(boxModelLanguageExtraB)); } else { BoxModelLanguage boxModelLanguage = new BoxModelLanguage(); boxModelLanguage = boxModelLanguageService.GetBoxModelLanguageWithBoxModelLanguageID(BoxModelLanguageID); if (boxModelLanguage == null) { return(NotFound()); } return(Ok(boxModelLanguage)); } } }
public void GetBoxModelLanguageList_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" }) { BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); boxModelLanguageService.Query = boxModelLanguageService.FillQuery(typeof(BoxModelLanguage), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "BoxModelLanguageID,GT,2|BoxModelLanguageID,LT,5", extra); List <BoxModelLanguage> boxModelLanguageDirectQueryList = new List <BoxModelLanguage>(); boxModelLanguageDirectQueryList = (from c in dbTestDB.BoxModelLanguages select c).Where(c => c.BoxModelLanguageID > 2 && c.BoxModelLanguageID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <BoxModelLanguage> boxModelLanguageList = new List <BoxModelLanguage>(); boxModelLanguageList = boxModelLanguageService.GetBoxModelLanguageList().ToList(); CheckBoxModelLanguageFields(boxModelLanguageList); Assert.AreEqual(boxModelLanguageDirectQueryList[0].BoxModelLanguageID, boxModelLanguageList[0].BoxModelLanguageID); } else { //Assert.AreEqual(true, false); } } } } }
public IHttpActionResult GetBoxModelLanguageList([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)) { BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { boxModelLanguageService.Query = boxModelLanguageService.FillQuery(typeof(BoxModelLanguageExtraA), lang, skip, take, asc, desc, where, extra); if (boxModelLanguageService.Query.HasErrors) { return(Ok(new List <BoxModelLanguageExtraA>() { new BoxModelLanguageExtraA() { HasErrors = boxModelLanguageService.Query.HasErrors, ValidationResults = boxModelLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(boxModelLanguageService.GetBoxModelLanguageExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { boxModelLanguageService.Query = boxModelLanguageService.FillQuery(typeof(BoxModelLanguageExtraB), lang, skip, take, asc, desc, where, extra); if (boxModelLanguageService.Query.HasErrors) { return(Ok(new List <BoxModelLanguageExtraB>() { new BoxModelLanguageExtraB() { HasErrors = boxModelLanguageService.Query.HasErrors, ValidationResults = boxModelLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(boxModelLanguageService.GetBoxModelLanguageExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { boxModelLanguageService.Query = boxModelLanguageService.FillQuery(typeof(BoxModelLanguage), lang, skip, take, asc, desc, where, extra); if (boxModelLanguageService.Query.HasErrors) { return(Ok(new List <BoxModelLanguage>() { new BoxModelLanguage() { HasErrors = boxModelLanguageService.Query.HasErrors, ValidationResults = boxModelLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(boxModelLanguageService.GetBoxModelLanguageList().ToList())); } } } }