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 BeerViewModel Get(int id) { using (var context = new BeerBoutiqueEntities()) { var beer = (from x in context.Beers where x.ID == id select x).FirstOrDefault(); if (beer != null) { var b = new BeerViewModel(beer); b.SimilarBeers = GetByStyle(beer.StyleID, 3); return b; } else throw new Exception("Not Found"); } }
public bool Update(BeerViewModel b) { using (var context = new BeerBoutiqueEntities()) { var oldBeer = (from x in context.Beers where x.ID == b.ID select x).FirstOrDefault(); if (oldBeer == null) { return false; } oldBeer.StyleID = b.StyleID; oldBeer.IBU = b.IBU; oldBeer.ABV = b.ABV; oldBeer.Description = b.Description; oldBeer.Name = b.Name; oldBeer.SRM = b.SRM; context.SaveChanges(); return true; } }