public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken) { if (request.Region == null || string.IsNullOrEmpty(request.Region.Code)) { throw new BusinessException("AddWrongInformation"); } var region = (await regionQueries.Gets($"r.code = '{request.Region.Code}' and r.is_deleted = 0")).FirstOrDefault(); if (region != null) { throw new BusinessException("Region.ExistedCode"); } var country = await countryQueries.Get(request.Region.CountryId); if (country == null) { throw new BusinessException("Country.NotExisted"); } request.Region = CreateBuild(request.Region, request.LoginSession); var rs = await regionRepository.Add(request.Region); return(rs == 0 ? -1 : 0); }
public async Task <APIResult> GetRegions() { return(new APIResult() { Result = 0, Data = await regionQueries.Gets() }); }
public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken) { if (request.Region == null || request.Region.Id == 0) { throw new BusinessException("Region.NotExisted"); } var region = await regionQueries.Get(request.Region.Id); if (region == null) { throw new BusinessException("Region.NotExisted"); } var checkingRegion = (await regionQueries.Gets($"r.code = '{request.Region.Code}' and r.id <> {region.Id} and r.is_deleted = 0")).FirstOrDefault(); if (checkingRegion != null) { throw new BusinessException("Region.ExistedCode"); } var country = await countryQueries.Get(request.Region.CountryId); if (country == null) { throw new BusinessException("Country.NotExisted"); } region = UpdateBuild(region, request.LoginSession); region.Code = request.Region.Code; region.Name = request.Region.Name; region.CountryId = request.Region.CountryId; region.IsUsed = request.Region.IsUsed; var rs = await regionRepository.Update(region); return(rs); }