Exemplo n.º 1
0
        public async Task CreateOrUpdateVillageInfo(VillageInfoCreateOrUpdateInput input)
        {
            await CheckValidation(input);

            if (input.Id.HasValue)
            {
                await UpdateVillageInfoAsync(input);
            }
            else
            {
                await CreateVillageInfoAsync(input);
            }
        }
Exemplo n.º 2
0
        private async Task CheckValidation(VillageInfoCreateOrUpdateInput input)
        {
            var existingObj = (await _villageInfoRepository.GetAll().AsNoTracking()
                               .FirstOrDefaultAsync(l => l.Code == input.Code && l.RegionInfoId == input.RegionInfoId));

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

            existingObj = (await _villageInfoRepository.GetAll().AsNoTracking()
                           .FirstOrDefaultAsync(l => l.Name == input.Name && l.RegionInfoId == input.RegionInfoId));
            if (existingObj != null && existingObj.Id != input.Id)
            {
                throw new UserFriendlyException(L("ThisNameAlreadyExists"));
            }
        }
Exemplo n.º 3
0
 private async Task CreateVillageInfoAsync(VillageInfoCreateOrUpdateInput input)
 {
     var villageInfo = ObjectMapper.Map <VillageInfo>(input);
     await _villageInfoRepository.InsertAsync(villageInfo);
 }