Esempio n. 1
0
        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"));
        }
Esempio n. 3
0
        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));
        }