public ActionResult Edit(int id, MowerEdit model) { if (!ModelState.IsValid) { //Populate(); return(View(model)); } if (model.MowerId != id) { //Populate(); ModelState.AddModelError("", "Mower Profile does not exist"); return(View(model)); } var service = CreateMowerService(); if (service.UpdateMower(model)) { TempData["SaveResult"] = "Your Mower Profile was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Mower Profile could not be updated."); return(View()); }
public IHttpActionResult Put(MowerEdit mower) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateMowerService(); if (!service.UpdateMower(mower)) { return(InternalServerError()); } return(Ok()); }
public ActionResult Edit(int id) { var service = CreateMowerService(); var detail = service.GetMowerById(id); var model = new MowerEdit { MowerId = detail.MowerId, MowerName = detail.MowerName, MowerCity = detail.MowerCity, MowerService = detail.MowerService, MowerRate = detail.MowerRate }; return(View(model)); }
// Read: Mower/Edit/{id} public ActionResult Edit(int id) { var service = CreateMowerService(); var detail = service.GetMowerById(id); var model = new MowerEdit { MowerId = detail.MowerId, FirstName = detail.FirstName, LastName = detail.LastName, LocationId = detail.LocationId, }; //Populate(); return(View(model)); }
public bool UpdateMower(MowerEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Mowers .Single(e => e.MowerId == model.MowerId && e.LandscapeId == _userId); entity.MowerId = model.MowerId; entity.MowerName = model.MowerName; entity.MowerCity = model.MowerCity; entity.MowerService = model.MowerService; entity.MowerRate = model.MowerRate; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, MowerEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.MowerId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateMowerService(); if (service.UpdateMower(model)) { TempData["SaveResult"] = "Your mower was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your mower could not be updated."); return(View(model)); }