Esempio n. 1
0
        public async Task CreateOrUpdateCityInfo(CityInfoCreateOrUpdateInput input)
        {
            await CheckValidation(input);

            if (input.Id.HasValue)
            {
                await UpdateCityInfoAsync(input);
            }
            else
            {
                await CreateCityInfoAsync(input);
            }
        }
Esempio n. 2
0
        private async Task CheckValidation(CityInfoCreateOrUpdateInput input)
        {
            var existingObj = (await _cityInfoRepository.GetAll().AsNoTracking()
                               .FirstOrDefaultAsync(l => l.Code == input.Code && l.StateInfoId == input.StateInfoId));

            if (existingObj != null && existingObj.Id != input.Id)
            {
                throw new UserFriendlyException(L("ThisCodeAlreadyExists"));
            }

            existingObj = (await _cityInfoRepository.GetAll().AsNoTracking()
                           .FirstOrDefaultAsync(l => l.Name == input.Name && l.StateInfoId == input.StateInfoId));
            if (existingObj != null && existingObj.Id != input.Id)
            {
                throw new UserFriendlyException(L("ThisNameAlreadyExists"));
            }
        }
Esempio n. 3
0
 private async Task CreateCityInfoAsync(CityInfoCreateOrUpdateInput input)
 {
     var cityInfo = ObjectMapper.Map <CityInfo>(input);
     await _cityInfoRepository.InsertAsync(cityInfo);
 }