public ActionResult Update(int CityID = -1) { logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name + "\" visited AccountsManagement/City/Update"); City city = repository.City.FirstOrDefault(c => c.CityID == CityID); if (city == null) { logger.Warn("City with id = " + CityID + " not found"); throw new HttpException(404, "City not found"); } var model = new viewModels.EditCityViewModel() { Country = city.Country.Name, CountryID = city.CountryID, City = city.Name, CityID = city.CityID, Area = city.Area, Region = city.Region }; return(View(model)); }
private ActionResult UpdateCity(viewModels.EditCityViewModel Model, int CityID = -1) { if (ModelState.IsValid) { // Attempt to register the user try { Country country = repository .Country .FirstOrDefault(c => c.CountryID == Model.CountryID); if (country == null) { ModelState.AddModelError("Country", "Страна не существует в базе"); return(View(Model)); } City city = repository .City .FirstOrDefault(c => c.Name == Model.City && c.Area == Model.Area && c.Region == Model.Region && c.CityID != CityID); if (city != null) { ModelState.AddModelError("City", "Город (населенный пункт) с таким именем уже существует"); return(View(Model)); } city = repository .City .FirstOrDefault(c => c.CityID == Model.CityID); if (city == null) { TempData["ErrorMessage"] = "Произошла ошибка при обновлении города (населенного пункта)"; logger.Warn("Error occured on user " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name + "\" city updating: city with id " + Model.CityID + " not exist"); return(View(Model)); } city.Name = Model.City; city.Area = Model.Area; city.Region = Model.Region; city.CountryID = country.CountryID; repository.AddCity(city); logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name + "\" update city \"" + Model.CityID + "\""); TempData["SuccessMessage"] = "Город (населенный пункт) успешно обновлен!"; return(RedirectToAction("Update", new { CityID = Model.CityID })); } catch (MembershipCreateUserException ex) { logger.Warn("Error occured on user " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name + "\" city updating: ", ex); TempData["ErrorMessage"] = "Произошла ошибка при обновлении города (населенного пункта)"; } } return(RedirectToAction("Update", new { CityID = CityID })); }
public ActionResult Update(viewModels.EditCityViewModel Model, int CityID = -1, string Update = null, string Delete = null, string Cancel = null) { if (CityID == -1) { logger.Warn("City with id = " + CityID + " not found"); throw new HttpException(404, "City not found"); } if (Delete != null) { return(DeleteCity(CityID)); } if (Cancel != null) { return(CancelCity()); } if (Update != null) { return(UpdateCity(Model, CityID)); } return(CancelCity()); }
public ActionResult Update(int CityID = -1) { logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) + " \"" + User.Identity.Name + "\" visited AccountsManagement/City/Update"); City city = repository.City.FirstOrDefault(c => c.CityID == CityID); if (city == null) { logger.Warn("City with id = " + CityID + " not found"); throw new HttpException(404, "City not found"); } var model = new viewModels.EditCityViewModel() { Country = city.Country.Name, CountryID = city.CountryID, City = city.Name, CityID = city.CityID, Area = city.Area, Region = city.Region }; return View(model); }