public async Task <IActionResult> Create() { var input = new CreateCityInputViewModel(); input.Regions = await this.castCollectionsService.GetRegionsAsKeyValuePairs(); return(this.View(input)); }
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); }
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)); }