コード例 #1
0
        public async Task <AdminCityAndCountryInputModel> GetCreateAsync()
        {
            AdminCityAndCountryInputModel model = new AdminCityAndCountryInputModel
            {
                CountryList = await this.context.
                              Countries
                              .OrderBy(c => c.Name)
                              .ToListAsync(),

                City = new City(),

                CityList = await this.context.Cities
                           .OrderBy(x => x.Name)
                           .Select(x => x.Name)
                           .Distinct()
                           .ToListAsync(),
            };

            return(model);
        }
コード例 #2
0
        public async Task <IActionResult> CreateAsync(AdminCityAndCountryInputModel model)
        {
            var modelVM = await this.adminCityService.GetCreateAsync();

            if (this.ModelState.IsValid)
            {
                var cityExists = await this.adminCityService.CreateAsync(model.City.Name, model.City.CountryId);

                if (cityExists == null)
                {
                    this.StatusMessage = RecordAlreadyExists;

                    modelVM.City          = model.City;
                    modelVM.StatusMessage = this.StatusMessage;

                    return(this.View(modelVM));
                }

                return(this.RedirectToAction(nameof(this.Index))
                       .WithSuccess(string.Empty, RecordCreatedSuccessfully));
            }

            return(this.View(modelVM));
        }