public ActionResult Edit(int id) { var service = CreateDiningService(); var detail = service.GetDiningById(id); var model = new DiningEdit { DiningId = detail.DiningId, NameOfRestaurant = detail.NameOfRestaurant, Location = detail.Location, ReservationTime = detail.ReservationTime, ReservationNumber = detail.ReservationNumber, }; return(View(model)); }
public bool UpdateDining(DiningEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Dinings .Single(e => e.DiningId == model.DiningId); entity.DiningId = model.DiningId; entity.NameOfRestaurant = model.NameOfRestaurant; entity.Location = model.Location; entity.ReservationTime = model.ReservationTime; entity.ReservationNumber = model.ReservationNumber; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, DiningEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.DiningId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateDiningService(); if (service.UpdateDining(model)) { TempData["SaveResult"] = "Your dining reservation was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your dining reservation could not be updated."); return(View(model)); }