public bool UpdatePantry(PantryEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Pantry .Single(e => e.PantryId == model.PantryId && e.OwnerId == _userId); entity.IngredientName = model.IngredientName; entity.InStock = model.InStock; entity.Location = model.Location; entity.Quantity = model.Quantity; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreatePantryService(); var detail = service.GetPantryDetailsById(id); var model = new PantryEdit { PantryId = detail.PantryId, IngredientName = detail.IngredientName, InStock = detail.InStock, Location = detail.Location, Quantity = detail.Quantity }; return(View(model)); }
public ActionResult Edit(int id, PantryEdit model) { if (!ModelState.IsValid) { return(View()); } if (model.PantryId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreatePantryService(); if (service.UpdatePantry(model)) { TempData["SaveResult"] = "Your Pantry was updated!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Pantry could not be updated."); return(View(model)); }