diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs index 64e3bb2..c0fbd9b 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs @@ -28,6 +28,7 @@ using Volo.Abp.Domain.Entities; using System.Security.Cryptography; using IdentityModel; using Microsoft.Extensions.Options; +using Volo.Abp; namespace Win_in.Sfs.Scp.WebApi { @@ -47,7 +48,7 @@ namespace Win_in.Sfs.Scp.WebApi public X12AsnAppService( IX12AsnRepository repository , ITenantRepository tenantRepository - , IOptions options + , IOptions options ) : base(repository) { @@ -95,11 +96,21 @@ namespace Win_in.Sfs.Scp.WebApi [Route("unread-list")] public async Task> GetUnreadListAsync(string site, int count, bool autoUpdateStatus) { - Validator.CheckSite(_tenantRepository, site); + try + { + Validator.CheckSite(_tenantRepository, site); - if (count < 1 || count > _options.Value.MaxCount) + if (count < 1 || count > _options.Value.MaxCount) + { + throw new UserFriendlyException($"Count must between 1 and {_options.Value.MaxCount}"); + } + } + catch (Exception ex) { - throw new AbpValidationException($"Count must bigger than 1 and smaller than {_options.Value.MaxCount}"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } var entities = await _x12AsnRepository.GetUnreadListAsync(site, count, autoUpdateStatus); @@ -122,11 +133,21 @@ namespace Win_in.Sfs.Scp.WebApi [Route("between-uid")] public async Task> GetListAsync(string site, long beginUid, long endUid) { - Validator.CheckSite(_tenantRepository, site); + try + { + Validator.CheckSite(_tenantRepository, site); - if (endUid < beginUid) + if (endUid < beginUid) + { + throw new UserFriendlyException("beginUid can not bigger than endUid"); + } + } + catch (Exception ex) { - throw new AbpValidationException("beginUid can not bigger than endUid"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.UID >= beginUid && p.UID <= endUid); @@ -148,13 +169,22 @@ namespace Win_in.Sfs.Scp.WebApi [Route("between-date")] public async Task> GetListAsync(string site, DateTime beginDate, DateTime endDate) { - Validator.CheckSite(_tenantRepository, site); + try + { + Validator.CheckSite(_tenantRepository, site); - if (endDate < beginDate) + if (endDate < beginDate) + { + throw new UserFriendlyException("beginDate can not after endDate"); + } + } + catch (Exception ex) { - throw new AbpValidationException("beginDate can not after endDate"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } - var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.EffectiveDate >= beginDate && p.EffectiveDate <= endDate); var dtos = BuildDtos(entities); @@ -173,16 +203,26 @@ namespace Win_in.Sfs.Scp.WebApi [Route("by-uid")] public async Task> GetAsync(string site, long uid) { - Validator.CheckSite(_tenantRepository, site); + X12Asn entity; + try + { + Validator.CheckSite(_tenantRepository, site); - var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.UID == uid); + entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.UID == uid); - if (entity == null) - { + if (entity == null) + { - throw new AbpValidationException($"ASN of {uid} in {site} is not found"); + throw new UserFriendlyException($"ASN of {uid} in {site} is not found"); + } + } + catch (Exception ex) + { + throw new AbpValidationException(new List + { + new(ex.Message) + }); } - var dto = BuildDto(entity); return dto; @@ -199,15 +239,26 @@ namespace Win_in.Sfs.Scp.WebApi [Route("by-number")] public async Task> GetAsync(string site, string number) { - Validator.CheckSite(_tenantRepository, site); + X12Asn entity; + try + { + Validator.CheckSite(_tenantRepository, site); - var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); - if (entity == null) + entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); + + if (entity == null) + { + throw new UserFriendlyException($"ASN of {number} in {site} is not found"); + } + } + catch (Exception ex) { - throw new AbpValidationException($"ASN of {number} in {site} is not found"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } - var dto = BuildDto(entity); return dto; @@ -232,15 +283,26 @@ namespace Win_in.Sfs.Scp.WebApi [Route("update-status")] public async Task> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status) { - Validator.CheckSite(_tenantRepository, site); + X12Asn entity; + try + { + Validator.CheckSite(_tenantRepository, site); + - var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); + entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); - if (entity == null) + if (entity == null) + { + throw new UserFriendlyException($"ASN of {number} in {site} is not found"); + } + } + catch (Exception ex) { - throw new AbpValidationException($"ASN of {number} in {site} is not found"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } - var result = await _x12AsnRepository.UpdateStatusAsync(entity.Id, status); var dto = BuildDto(result);