public async Task <IActionResult> Create(CityCreateInputModel cityCreateInputModel) { await this.cityService.CreateCity(cityCreateInputModel); return(this.Redirect(AuctionHouseCreateRoute)); }
public async Task <IActionResult> Create(CityCreateInputModel model) { bool isCityExisits = await this.citiesService.IsCityExistsAsync(model.Name, model.CountryId); if (isCityExisits) { this.ModelState.AddModelError("Name", "Provided city name already exists"); } if (!this.ModelState.IsValid) { var countries = await this.countriesService.GetAllCountriesAsync(); model.Countries = countries.Select(c => new SelectListItem { Text = c.Name, Value = c.Id }) .ToList(); return(this.View(model)); } await this.citiesService.CreateCityAsync(model.Name, model.CountryId); return(RedirectToAction("Index")); }
public async Task <bool> CreateCity(CityCreateInputModel inputModel) { City city = new City { Name = inputModel.Name }; context.Cities.Add(city); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task <IActionResult> Create() { var countries = await this.countriesService.GetAllCountriesAsync(); var viewModel = new CityCreateInputModel() { Countries = countries.Select(c => new SelectListItem { Text = c.Name, Value = c.Id }) .ToList() }; return(this.View(viewModel)); }
public async Task Create_WithCorrectData_ShouldReturnSuccessfullyCreate() { string errorMessagePrefix = "CityService CreateCity() does not work properly."; var context = AuctionDbContextInMemory.InitializeContext(); await SeedData(context); this.cityService = new CityService(context); var testAuctionHouse = new CityCreateInputModel { Name = "Sofia" }; bool actualResult = await this.cityService.CreateCity(testAuctionHouse); Assert.True(actualResult, errorMessagePrefix); }