public ActionResult Edit(int id) { var service = CreatePlatingService(); var detail = service.GetPlatingbyId(id); var model = new PlatingEdit() { ID = detail.ID, Name = detail.Name, Description = detail.Description }; return(View(model)); }
public bool UpdatePlating(PlatingEdit model) { using (var context = new CookbookContext()) { var entity = context .Platings .Single(e => e.ID == model.ID && e.AuthorID == userId); entity.Name = model.Name; entity.Description = model.Description; entity.DateModified = DateTimeOffset.UtcNow; return(context.SaveChanges() == 1); } }
public ActionResult Edit(int id, PlatingEdit model) { if (!ModelState.IsValid) { return(View(model)); } else if (model.ID != id) { ModelState.AddModelError("", "Id mismatch"); return(View(model)); } var service = CreatePlatingService(); if (service.UpdatePlating(model)) { TempData["Save Result"] = "Your Plating was updated."; return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Your Plating could not be updated."); return(View(model)); } }