public ActionResult Edit(int id) { var service = CreateShoppingService(); var detail = service.GetShoppingById(id); var model = new ShoppingEdit { ShoppingId = detail.ShoppingId, ShoppingLiquor = detail.ShoppingLiquor, ShoppingFruit = detail.ShoppingFruit, ShoppingJuice = detail.ShoppingJuice, ShoppingOther = detail.ShoppingOther }; return(View(model)); }
public bool UpdateShopping(ShoppingEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .ShoppingList .Single(e => e.ShoppingId == model.ShoppingId && e.OwnerId == _userId); entity.ShoppingId = model.ShoppingId; entity.ShoppingLiquor = model.ShoppingLiquor; entity.ShoppingJuice = model.ShoppingJuice; entity.ShoppingFruit = model.ShoppingFruit; entity.ShoppingOther = model.ShoppingOther; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, ShoppingEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ShoppingId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateShoppingService(); if (service.UpdateShopping(model)) { TempData["SaveResult"] = "Your note was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your note could not be updated."); return(View(model)); }