示例#1
0
        public async Task CreateAirportAsync(AirportCreateInputModel model)
        {
            var airport = this.mapper.Map <Airport>(model);

            this.dbContext.Airports.Add(airport);
            await this.dbContext.SaveChangesAsync();
        }
示例#2
0
        public async Task <IActionResult> Create()
        {
            var model = new AirportCreateInputModel();

            model.Cities = await this.citiesService.GetAllCitiesAsDropdownListAsync();

            return(View(model));
        }
示例#3
0
        public async Task <AirportCreateInputModel> GetAirportCreateInputModelAsync()
        {
            var model = new AirportCreateInputModel();

            model.Cities = await this.citiesService.GetAllCitiesAsDropdownListAsync();

            return(model);
        }
示例#4
0
        public async Task <IActionResult> Create(AirportCreateInputModel model)
        {
            bool isAirportExists = await this.airportsService.IsAirportExistsAsync(model.IcaoCode);

            if (isAirportExists)
            {
                this.ModelState.AddModelError("IcaoCode", "Provided ICAO Code already exists");
            }

            if (!this.ModelState.IsValid)
            {
                model.Cities = await this.citiesService.GetAllCitiesAsDropdownListAsync();

                return(this.View(model));
            }

            await this.airportsService.CreateAirportAsync(model);

            return(RedirectToAction("Index"));
        }