public async Task <CountryModel> AddAsync(CountryModel countryModel)
        {
            CountryEntity country = _mapper.Map <CountryEntity>(countryModel);

            bool countryDuplicate = await _countryRepository.CheckDuplicateAsync(country);

            if (countryDuplicate)
            {
                throw new InvalidDataException("This country already exists");
            }

            await _countryRepository.AddAsync(country);

            return(countryModel);
        }
示例#2
0
        public async Task <AddResult> AddAsync(Country country)
        {
            CountryEntity countryDal = _mapper.Map <CountryEntity>(country);

            bool duplicate = await _countryRepository.CheckDuplicateAsync(countryDal);

            if (duplicate)
            {
                return(new AddResult(ResultTypes.Duplicate, null));
            }

            int addedCountryId = await _countryRepository.AddAsync(countryDal);

            return(new AddResult(ResultTypes.Ok, addedCountryId));
        }