public IHttpActionResult GetMapInfoWithID([FromUri] int MapInfoID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MapInfoService mapInfoService = new MapInfoService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); mapInfoService.Query = mapInfoService.FillQuery(typeof(MapInfo), lang, 0, 1, "", "", extra); if (mapInfoService.Query.Extra == "A") { MapInfoExtraA mapInfoExtraA = new MapInfoExtraA(); mapInfoExtraA = mapInfoService.GetMapInfoExtraAWithMapInfoID(MapInfoID); if (mapInfoExtraA == null) { return(NotFound()); } return(Ok(mapInfoExtraA)); } else if (mapInfoService.Query.Extra == "B") { MapInfoExtraB mapInfoExtraB = new MapInfoExtraB(); mapInfoExtraB = mapInfoService.GetMapInfoExtraBWithMapInfoID(MapInfoID); if (mapInfoExtraB == null) { return(NotFound()); } return(Ok(mapInfoExtraB)); } else { MapInfo mapInfo = new MapInfo(); mapInfo = mapInfoService.GetMapInfoWithMapInfoID(MapInfoID); if (mapInfo == null) { return(NotFound()); } return(Ok(mapInfo)); } } }
public void GetMapInfoList_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" }) { MapInfoService mapInfoService = new MapInfoService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); mapInfoService.Query = mapInfoService.FillQuery(typeof(MapInfo), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "MapInfoID,GT,2|MapInfoID,LT,5", extra); List <MapInfo> mapInfoDirectQueryList = new List <MapInfo>(); mapInfoDirectQueryList = (from c in dbTestDB.MapInfos select c).Where(c => c.MapInfoID > 2 && c.MapInfoID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <MapInfo> mapInfoList = new List <MapInfo>(); mapInfoList = mapInfoService.GetMapInfoList().ToList(); CheckMapInfoFields(mapInfoList); Assert.AreEqual(mapInfoDirectQueryList[0].MapInfoID, mapInfoList[0].MapInfoID); } else { //Assert.AreEqual(true, false); } } } } }
public IHttpActionResult GetMapInfoList([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)) { MapInfoService mapInfoService = new MapInfoService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { mapInfoService.Query = mapInfoService.FillQuery(typeof(MapInfoExtraA), lang, skip, take, asc, desc, where, extra); if (mapInfoService.Query.HasErrors) { return(Ok(new List <MapInfoExtraA>() { new MapInfoExtraA() { HasErrors = mapInfoService.Query.HasErrors, ValidationResults = mapInfoService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mapInfoService.GetMapInfoExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { mapInfoService.Query = mapInfoService.FillQuery(typeof(MapInfoExtraB), lang, skip, take, asc, desc, where, extra); if (mapInfoService.Query.HasErrors) { return(Ok(new List <MapInfoExtraB>() { new MapInfoExtraB() { HasErrors = mapInfoService.Query.HasErrors, ValidationResults = mapInfoService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mapInfoService.GetMapInfoExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { mapInfoService.Query = mapInfoService.FillQuery(typeof(MapInfo), lang, skip, take, asc, desc, where, extra); if (mapInfoService.Query.HasErrors) { return(Ok(new List <MapInfo>() { new MapInfo() { HasErrors = mapInfoService.Query.HasErrors, ValidationResults = mapInfoService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mapInfoService.GetMapInfoList().ToList())); } } } }