public async Task <ProvinceDto> AddOrUpdate(ProvinceInputDto input) { var province = _provinceRepository.FirstOrDefault(x => x.Id == input.Id); var isNew = province == null; // -- Check if exist Code var existCode = await _provinceRepository.FirstOrDefaultAsync(x => (isNew || (!isNew && x.Id != input.Id)) && x.CountryId == input.CountryId && x.Code.ToLower() == input.Code.ToLower().Trim()); if (existCode != null) { throw new UserFriendlyException("This Code already exists"); } // -- Check if exist SubDivisionName var existSubDivisionName = await _provinceRepository.FirstOrDefaultAsync(x => (isNew || (!isNew && x.Id != input.Id)) && x.CountryId == input.CountryId && x.SubDivisionName.ToLower() == input.SubDivisionName.ToLower().Trim()); if (existSubDivisionName != null) { throw new UserFriendlyException("This Sub Division Name already exists"); } var provinceLocal = ObjectMapper.Map(input, province); province = await _provinceRepository.InsertOrUpdateAsync(provinceLocal); await CurrentUnitOfWork.SaveChangesAsync(); return(ObjectMapper.Map <ProvinceDto>(province)); }
public async Task <List <NameValue <string> > > GetCitys(ProvinceInputDto input) { var result = new List <NameValue <string> >(); var datas = (await AsyncQueryableExecuter.ToListAsync(Repository.GetAll().Where(m => m.Country == input.Country && m.Province == input.Province))) .Select(m => new { Id = m.City, Name = m.City }).Distinct().ToList(); foreach (var data in datas) { var value = new NameValue() { Value = data.Id.ToString(), Name = data.Name }; result.Add(value); } return(result); }