public ActionResult Edit(int id) { var service = CreateHairServiceService(); var detail = service.GetServiceByID(id); var model = new HairServiceEdit { HairServiceID = detail.HairServiceID, ServiceType = detail.ServiceType, Name = detail.Name, Description = detail.Description, Price = detail.Price }; return(View(model)); }
public bool UpdateHairService(HairServiceEdit model) { using (var hs = new ApplicationDbContext()) { var entity = hs .HairServices .Single(e => e.HairServiceId == model.HairServiceID && e.OwnerID == _userId); entity.ServiceType = model.ServiceType; entity.Name = model.Name; entity.Description = model.Description; entity.Price = model.Price; return(hs.SaveChanges() == 1); } }
public ActionResult Edit(int id, HairServiceEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.HairServiceID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateHairServiceService(); if (service.UpdateHairService(model)) { TempData["SaveResult"] = "Your service was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your service could not be updated."); return(View(model)); }