public ActionResult CityEdit(int id = 0) { if (!checkRight()) { return(Login()); } initMenu(AdminMenuType.CitySettings); bool error = false; if (Request.HttpMethod == "POST") { string cityName = RequestHelper.GetRequestFormText(Request, "cityname"); if (string.IsNullOrEmpty(cityName)) { //ошибка error = true; } else { if (id == 0) { FormRepository.AddCity(cityName); } else { FormRepository.UpdateCity(id, cityName); } return(Redirect(AdminLinkBuilder.CityList())); } } var vm = new AdminCityEditViewModel(); vm.Error = error; vm.City = FormRepository.GetCity(id); vm.CityName = ""; if (vm.City == null || vm.City.ID == 0) { vm.IsNew = true; } else if (!error) { vm.CityName = vm.City.CityName; } return(View("AdminCityEditPage", vm)); }