public IHttpActionResult GetMWQMSubsectorWithID([FromUri] int MWQMSubsectorID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMSubsectorService mwqmSubsectorService = new MWQMSubsectorService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); mwqmSubsectorService.Query = mwqmSubsectorService.FillQuery(typeof(MWQMSubsector), lang, 0, 1, "", "", extra); if (mwqmSubsectorService.Query.Extra == "A") { MWQMSubsectorExtraA mwqmSubsectorExtraA = new MWQMSubsectorExtraA(); mwqmSubsectorExtraA = mwqmSubsectorService.GetMWQMSubsectorExtraAWithMWQMSubsectorID(MWQMSubsectorID); if (mwqmSubsectorExtraA == null) { return(NotFound()); } return(Ok(mwqmSubsectorExtraA)); } else if (mwqmSubsectorService.Query.Extra == "B") { MWQMSubsectorExtraB mwqmSubsectorExtraB = new MWQMSubsectorExtraB(); mwqmSubsectorExtraB = mwqmSubsectorService.GetMWQMSubsectorExtraBWithMWQMSubsectorID(MWQMSubsectorID); if (mwqmSubsectorExtraB == null) { return(NotFound()); } return(Ok(mwqmSubsectorExtraB)); } else { MWQMSubsector mwqmSubsector = new MWQMSubsector(); mwqmSubsector = mwqmSubsectorService.GetMWQMSubsectorWithMWQMSubsectorID(MWQMSubsectorID); if (mwqmSubsector == null) { return(NotFound()); } return(Ok(mwqmSubsector)); } } }
public void GetMWQMSubsectorList_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" }) { MWQMSubsectorService mwqmSubsectorService = new MWQMSubsectorService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); mwqmSubsectorService.Query = mwqmSubsectorService.FillQuery(typeof(MWQMSubsector), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "MWQMSubsectorID,GT,2|MWQMSubsectorID,LT,5", extra); List <MWQMSubsector> mwqmSubsectorDirectQueryList = new List <MWQMSubsector>(); mwqmSubsectorDirectQueryList = (from c in dbTestDB.MWQMSubsectors select c).Where(c => c.MWQMSubsectorID > 2 && c.MWQMSubsectorID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <MWQMSubsector> mwqmSubsectorList = new List <MWQMSubsector>(); mwqmSubsectorList = mwqmSubsectorService.GetMWQMSubsectorList().ToList(); CheckMWQMSubsectorFields(mwqmSubsectorList); Assert.AreEqual(mwqmSubsectorDirectQueryList[0].MWQMSubsectorID, mwqmSubsectorList[0].MWQMSubsectorID); } else { //Assert.AreEqual(true, false); } } } } }
public IHttpActionResult GetMWQMSubsectorList([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)) { MWQMSubsectorService mwqmSubsectorService = new MWQMSubsectorService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { mwqmSubsectorService.Query = mwqmSubsectorService.FillQuery(typeof(MWQMSubsectorExtraA), lang, skip, take, asc, desc, where, extra); if (mwqmSubsectorService.Query.HasErrors) { return(Ok(new List <MWQMSubsectorExtraA>() { new MWQMSubsectorExtraA() { HasErrors = mwqmSubsectorService.Query.HasErrors, ValidationResults = mwqmSubsectorService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmSubsectorService.GetMWQMSubsectorExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { mwqmSubsectorService.Query = mwqmSubsectorService.FillQuery(typeof(MWQMSubsectorExtraB), lang, skip, take, asc, desc, where, extra); if (mwqmSubsectorService.Query.HasErrors) { return(Ok(new List <MWQMSubsectorExtraB>() { new MWQMSubsectorExtraB() { HasErrors = mwqmSubsectorService.Query.HasErrors, ValidationResults = mwqmSubsectorService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmSubsectorService.GetMWQMSubsectorExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { mwqmSubsectorService.Query = mwqmSubsectorService.FillQuery(typeof(MWQMSubsector), lang, skip, take, asc, desc, where, extra); if (mwqmSubsectorService.Query.HasErrors) { return(Ok(new List <MWQMSubsector>() { new MWQMSubsector() { HasErrors = mwqmSubsectorService.Query.HasErrors, ValidationResults = mwqmSubsectorService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmSubsectorService.GetMWQMSubsectorList().ToList())); } } } }