public ActionResult Edit(BeerViewModel beer) { if (ModelState.IsValid) { var beerFacade = new BeerFacade(); beerFacade.Update(beer); return View(); } else { throw new Exception("Invalid Model State"); } }
public JsonResult GetTop(BeerStyle? style = null) { int echo = 0; if (Request["sEcho"] != null) { if (!Int32.TryParse(Request["sEcho"], out echo)) { throw new HttpRequestException("XSS Attack possibly attempted"); } } var beerFacade = new BeerFacade(); var res = beerFacade.Top(style); return Json(new { iTotalRecords = res.Count(), iTotalDisplayRecords = res.Count(), sEcho = echo, aaData = res.Select(x => new[] { x.Name, x.Style, x.ABV.ToString(), x.AverageOverall.ToString(), x.ID.ToString() }) }, JsonRequestBehavior.AllowGet); }
public JsonResult GetByStyle(int id) { var echo = 0; var take = 0; var skip = 0; if (Request["sEcho"] != null) { if (!Int32.TryParse(Request["sEcho"], out echo)) { throw new HttpRequestException("XSS Attack possibly attempted"); } } if (Request["iDisplayStart"] != null) { if (!Int32.TryParse(Request["iDisplayStart"], out skip)) { skip = 0; } } if (Request["iDisplayLength"] != null) { if (!Int32.TryParse(Request["iDisplayLength"], out take)) { take = 50; } } var beerFacade = new BeerFacade(); var beers = beerFacade.GetByStyle(id); return Json(new { iTotalRecords = beers.Count(), iTotalDisplayRecords = beers.Count(), sEcho = echo, aaData = beers.Skip(skip).Take(take).Select(x => new[] { x.Name, x.Style, x.ABV.ToString(), x.AverageOverall.ToString(), x.ID.ToString() }) }, JsonRequestBehavior.AllowGet); }