public async Task <IActionResult> CreateCity(CreateCityInputModel input) { if (!await this.countriesService.CheckIfCountryExists(input.CountryId)) { return(this.NotFound()); } await this.citiesService.CreateAsync(input.Name, input.CountryId); return(this.RedirectToAction("Index")); }
public async Task <IActionResult> Create([FromForm] CreateCityInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var isCreate = await this.cityService.CreateAsync(model.Name); if (isCreate) { this.TempData["CreateCity"] = $"Град {model.Name} е добавен към списъка!"; } return(this.RedirectToAction("All")); }
public async Task <IActionResult> CreateCity() { var countries = await this.countriesService.GetAll <CountryServiceModel>(); var model = new CreateCityInputModel() { Countries = countries .Select(c => new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), }), }; return(this.View(model)); }