public ActionResult City(string error, string success) { var cityAddModel = new CityAddViewModel(); if (error != null) { cityAddModel.Error = error; } if (success != null) { cityAddModel.Success = success; } return(View(cityAddModel)); }
public virtual ActionResult CreateCity(CityAddViewModel cityViewModel) { var city = new City() { Name = cityViewModel.Name, Province = _provinceService.GetById(cityViewModel.ProvinceId) }; _cityService.Create(city); if (_unitOfWork.SaveAllChanges() > 0) { return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel { Alert = AlertOperation.SurveyOperation(StatusOperation.SuccsessInsert), Status = AlertMode.success })); } else { return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel { Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning })); } }
public ActionResult City(CityAddViewModel model) { var otherCities = this.cityService.GetAllNames(); if (model.Name == null || model.Name.Length < 3 || !(model.Name is string)) { return(this.RedirectToAction("City", new { error = "Error! Name of city must be a string with 3 or more symbols!" })); } if (otherCities.Contains(model.Name)) { return(this.RedirectToAction("City", new { error = $"Error! City {model.Name} already exists!" })); } int result = this.cityService.AddByName(model.Name); if (result <= 0) { return(this.RedirectToAction("City", new { error = $"Error! City {model.Name} was not created!" })); } return(this.RedirectToAction("City", new { success = $"Success! City {model.Name} was added to database!" })); }
public async Task <IActionResult> AddCity(Guid countryId, [FromBody] CityAddViewModel city) { if (city == null) { return(BadRequest()); } if (!await countryRepository.CountryExists(countryId)) { return(NotFound()); } var cityModel = mapper.Map <City>(city); await cityRepository.AddCityForCountry(countryId, cityModel); if (!await unitOfWork.SaveAsync()) { return(StatusCode(500, "server error")); } var cityResource = mapper.Map <CityResource>(cityModel); return(CreatedAtAction(nameof(GetCity), new { countryId, cityId = cityModel.Id }, CreateLinksFactory(cityResource))); }