public ActionResult Edit(int id) { var service = CreateHorseService(); var detail = service.GetHorseById(id); var model = new HorseEdit { Name = detail.Name, ClientId = detail.ClientId }; return(View(model)); }
public bool UpdateHorse(HorseEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Horses .Single(e => e.HorseId == model.HorseId); entity.Name = model.Name; entity.ClientId = model.ClientId; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateHorseService(); var detail = service.GetHorseById(id); var model = new HorseEdit { HorseId = detail.HorseId, HorseName = detail.HorseName, Color = detail.Color, Age = detail.Age, Height = detail.Height, Weight = detail.Weight, Sex = detail.Sex, Breed = detail.Breed, IntakeNotes = detail.IntakeNotes }; return(View(model)); }
public ActionResult Edit(int id, HorseEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.HorseId != id) { ModelState.AddModelError("", "The HorseId entered does not match."); return(View(model)); } var service = CreateHorseService(); if (service.UpdateHorse(model)) { TempData["SaveResult"] = "The horse's information has been updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Unable to update."); return(View(model)); }
public ActionResult Edit(int id, HorseEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.HorseId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateHorseService(); if (service.UpdateHorse(model)) { TempData["SaveResult"] = "Horse updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Horse could not be updated."); return(View(model)); }