| | |
| | | public class EnterpriseCommandHandler( |
| | | IRepository<Enterprise> rep, |
| | | IRepository<UserInfo> repUserInfo |
| | | ) |
| | | : IRequestHandler<SaveEnterpriseCommand, Guid> |
| | | ) : |
| | | IRequestHandler<SaveEnterpriseCommand, Guid>, |
| | | IRequestHandler<SetEnterpriseElectronSignSettingCommand, Guid>, |
| | | IRequestHandler<SetEnterpriseSmsSettingCommand, Guid> |
| | | |
| | | { |
| | | private readonly IRepository<Enterprise> rep = rep; |
| | | private readonly IRepository<UserInfo> repUserInfo = repUserInfo; |
| | |
| | | public async Task<Guid> Handle(SaveEnterpriseCommand request, CancellationToken cancellationToken) |
| | | { |
| | | var entity = await rep.AsQueryable() |
| | | .FirstOrDefaultAsync(it => it.SocietyCreditCode == request.SocietyCreditCode); |
| | | .Include(it => it.EnterpriseAuth) |
| | | .FirstOrDefaultAsync(it => it.EnterpriseAuth.SocietyCreditCode == request.EnterpriseAuth.SocietyCreditCode); |
| | | if (entity == null) |
| | | { |
| | | entity = new Enterprise(); |
| | | entity.EnterpriseAuth = new EnterpriseAuth(); |
| | | request.Adapt(entity); |
| | | await rep.InsertAsync(entity); |
| | | } |
| | |
| | | |
| | | return entity.Id; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置企业电子签配置 |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public async Task<Guid> Handle(SetEnterpriseElectronSignSettingCommand request, CancellationToken cancellationToken) |
| | | { |
| | | var entity = await rep.AsQueryable().FirstOrDefaultAsync(it => it.Id == request.Id, cancellationToken); |
| | | if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "该企业"); |
| | | request.Adapt(entity); |
| | | await rep.UpdateAsync(entity); |
| | | return entity.Id; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置企业短信配置 |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public async Task<Guid> Handle(SetEnterpriseSmsSettingCommand request, CancellationToken cancellationToken) |
| | | { |
| | | var entity = await rep.AsQueryable().FirstOrDefaultAsync(it => it.Id == request.Id, cancellationToken); |
| | | if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "该企业"); |
| | | request.Adapt(entity); |
| | | await rep.UpdateAsync(entity); |
| | | return entity.Id; |
| | | } |
| | | } |
| | | } |