public ActionResult Edit(int id, BusinessEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var businessService = CreateBusinessService(); string result = (businessService.Update(model, id)); if (result == "Okay") { TempData["SaveResult"] = "Business updated!"; return(RedirectToAction($"Details/{id}")); } //if (result == "invalid city") // ModelState.AddModelError("", $"{model.City} could not be found."); else { ModelState.AddModelError("", "Business could not be updated."); } return(View(model)); }
public string Update(BusinessEdit model, int id) { using (var ctx = new ApplicationDbContext()) { var service = new CityService(); //var foundCity = service.GetCityByName(model.City, model.State); //if (foundCity == null) return "invalid city"; var entity = ctx.Businesses.Single(e => e.ID == id); entity.ID = model.ID; entity.Name = model.Name; entity.CityID = model.CityID; entity.TypeOfEstablishment = $"{model.typeOfEstablishment}"; entity.ZipCode = model.ZipCode; entity.Hours = model.Hours; entity.PhoneNumber = model.PhoneNumber; entity.Website = model.Website; try { ctx.SaveChanges(); return("Okay"); } catch { } return("True"); } }
public ActionResult Edit(int id) { var businessService = CreateBusinessService(); var detail = businessService.GetByID(id); var model = new BusinessEdit { ID = detail.ID, Name = detail.Name, CityID = detail.CityID, State = detail.State, ZipCode = detail.ZipCode, Hours = detail.Hours, PhoneNumber = detail.PhoneNumber, Website = detail.Website, }; return(View(model)); }