public async Task <bool> ImportDistrictFromAPIAsync(UserIdentity <int> issuer) { try { var provinces = await _provinceRepository.GetProvinces().MapQueryTo <ProvinceModel>(_mapper).ToListAsync(); foreach (ProvinceModel provinceModel in provinces) { // UPDATE GET FROM APPSETTING var url = "https://thongtindoanhnghiep.co/api/city/" + provinceModel.Code + "/district"; var APIItems = await GetDistrictFromAPIAsync(url); if (APIItems != null) { foreach (APIDistrictModel item in APIItems) { var district = new District() { Name = item.Title, Code = item.Id.ToString(), Type = item.Type, ProvinceId = provinceModel.Id }; district.CreateBy(issuer).UpdateBy(issuer); _districtRepository.Create(district); } } } if (await _uow.SaveChangesAsync() > 0) { return(true); } return(false); } catch (Exception e) { throw e; } }