public async Task <IActionResult> Create(CountryCreateInputModel countryCreateInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(countryCreateInputModel));
            }

            await this.countriesService.CreateAsync(countryCreateInputModel);

            return(this.RedirectToAction("GetAll", "Countries", new { area = "Administration" }));
        }
Esempio n. 2
0
        public async Task CheckSettingOfCountryProperties()
        {
            var model = new CountryCreateInputModel
            {
                Name = "Germany",
            };

            await this.countriesService.CreateAsync(model);

            var country = await this.countriesRepository.All().FirstOrDefaultAsync();

            Assert.Equal("Germany", country.Name);
        }
Esempio n. 3
0
        public async Task TestAddingCountry()
        {
            var model = new CountryCreateInputModel
            {
                Name = "China",
            };

            await this.countriesService.CreateAsync(model);

            var count = await this.countriesRepository.All().CountAsync();

            Assert.Equal(1, count);
        }
Esempio n. 4
0
        public async Task CheckIfAddingCountryReturnsViewModel()
        {
            var country = new CountryCreateInputModel
            {
                Name = "Germany",
            };

            var viewModel = await this.countriesService.CreateAsync(country);

            var dbEntry = await this.countriesRepository.All().FirstOrDefaultAsync();

            Assert.Equal(dbEntry.Id, viewModel.Id);
            Assert.Equal(dbEntry.Name, viewModel.Name);
        }
Esempio n. 5
0
        public async Task CheckIfAddingCountryThrowsArgumentException()
        {
            this.SeedDatabase();

            var country = new CountryCreateInputModel
            {
                Name = "Bulgaria",
            };

            var exception = await Assert
                            .ThrowsAsync <ArgumentException>(async() => await this.countriesService.CreateAsync(country));

            Assert.Equal(string.Format(ExceptionMessages.CountryAlreadyExists, country.Name), exception.Message);
        }
Esempio n. 6
0
        public async Task <ActionResult> Create(CountryCreateInputModel model)
        {
            bool isExisits = await this.countriesService.IsCountryExistsAsync(model.Name);

            if (isExisits)
            {
                this.ModelState.AddModelError("Name", "Provided country name already exists");
            }

            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            await this.countriesService.CreateCountryAsync(model.Name);

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 7
0
        public async Task <CountryDetailsViewModel> CreateAsync(CountryCreateInputModel countryCreateInputModel)
        {
            var country = new Country
            {
                Name = countryCreateInputModel.Name,
            };

            bool doesCountryExist = await this.countriesRepository.All().AnyAsync(x => x.Name == country.Name);

            if (doesCountryExist)
            {
                throw new ArgumentException(
                          string.Format(ExceptionMessages.CountryAlreadyExists, country.Name));
            }

            await this.countriesRepository.AddAsync(country);

            await this.countriesRepository.SaveChangesAsync();

            var viewModel = await this.GetViewModelByIdAsync <CountryDetailsViewModel>(country.Id);

            return(viewModel);
        }