Exemplo n.º 1
0
        public async Task <IActionResult> Create()
        {
            var input = new CreateCityInputViewModel();

            input.Regions = await this.castCollectionsService.GetRegionsAsKeyValuePairs();

            return(this.View(input));
        }
Exemplo n.º 2
0
        public async Task <bool> CreateAsync(CreateCityInputViewModel input)
        {
            if (this.citiesRepository.AllWithDeleted().Any(x => x.Name == input.Name && x.IsDeleted == false))
            {
                return(false);
            }

            var newCity = new City
            {
                Name     = input.Name,
                RegionId = input.RegionId,
            };

            await this.citiesRepository.AddAsync(newCity);

            await this.citiesRepository.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(CreateCityInputViewModel input)
        {
            if (this.ModelState.IsValid)
            {
                var isCreated = await this.citiesService.CreateAsync(input);

                if (!isCreated)
                {
                    this.TempData["Message"] = $"Already have city with {input.Name} name.";
                }

                return(this.RedirectToAction(nameof(this.Index)));
            }

            var inputModel = new CreateCityInputViewModel();

            inputModel.Regions = await this.castCollectionsService.GetRegionsAsKeyValuePairs();

            return(this.View(inputModel));
        }