public IHttpActionResult GetRainExceedanceWithID([FromUri] int RainExceedanceID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { RainExceedanceService rainExceedanceService = new RainExceedanceService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); rainExceedanceService.Query = rainExceedanceService.FillQuery(typeof(RainExceedance), lang, 0, 1, "", "", extra); if (rainExceedanceService.Query.Extra == "A") { RainExceedanceExtraA rainExceedanceExtraA = new RainExceedanceExtraA(); rainExceedanceExtraA = rainExceedanceService.GetRainExceedanceExtraAWithRainExceedanceID(RainExceedanceID); if (rainExceedanceExtraA == null) { return(NotFound()); } return(Ok(rainExceedanceExtraA)); } else if (rainExceedanceService.Query.Extra == "B") { RainExceedanceExtraB rainExceedanceExtraB = new RainExceedanceExtraB(); rainExceedanceExtraB = rainExceedanceService.GetRainExceedanceExtraBWithRainExceedanceID(RainExceedanceID); if (rainExceedanceExtraB == null) { return(NotFound()); } return(Ok(rainExceedanceExtraB)); } else { RainExceedance rainExceedance = new RainExceedance(); rainExceedance = rainExceedanceService.GetRainExceedanceWithRainExceedanceID(RainExceedanceID); if (rainExceedance == null) { return(NotFound()); } return(Ok(rainExceedance)); } } }
public void GetRainExceedanceWithRainExceedanceID__rainExceedance_RainExceedanceID__Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { RainExceedanceService rainExceedanceService = new RainExceedanceService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); RainExceedance rainExceedance = (from c in dbTestDB.RainExceedances select c).FirstOrDefault(); Assert.IsNotNull(rainExceedance); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { rainExceedanceService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { RainExceedance rainExceedanceRet = rainExceedanceService.GetRainExceedanceWithRainExceedanceID(rainExceedance.RainExceedanceID); CheckRainExceedanceFields(new List <RainExceedance>() { rainExceedanceRet }); Assert.AreEqual(rainExceedance.RainExceedanceID, rainExceedanceRet.RainExceedanceID); } else { //Assert.AreEqual(true, false); } } } } }