public ActionResult Edit(int id) { var service = CreateRepairShopService(); var detail = service.GetRepairShopById(id); var model = new RepairShopEdit { RepairShopId = detail.RepairShopId, CustomerId = detail.CustomerId, CustomerFirstName = detail.CustomerFirstName, CustomerLastName = detail.CustomerLastName, VehicleId = detail.VehicleId, VehicleMake = detail.VehicleMake, VehicleModel = detail.VehicleModel, ServiceId = detail.ServiceId, ServiceTotalCost = detail.ServiceTotalCost }; return(View(model)); }
public bool UpdateRepairShop(RepairShopEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .RepairShops .Single(e => e.RepairShopId == model.RepairShopId); entity.CustomerId = model.CustomerId; entity.CustomerFirstName = model.CustomerFirstName; entity.CustomerLastName = model.CustomerLastName; entity.VehicleId = model.VehicleId; entity.VehicleMake = model.VehicleMake; entity.VehicleModel = model.VehicleModel; entity.ServiceId = model.ServiceId; entity.ServiceTotalCost = model.ServiceTotalCost; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, RepairShopEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.RepairShopId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateRepairShopService(); if (service.UpdateRepairShop(model)) { TempData["SaveResult"] = "Your ticket was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your ticket could not be updated."); return(View(model)); }