refactor(ModifyDocStatusCommandBase): add EnvelopeId and ReceiverId properties
This commit is contained in:
@@ -8,6 +8,21 @@ namespace EnvelopeGenerator.Application.DocStatus.Commands;
|
||||
/// </summary>
|
||||
public record ModifyDocStatusCommandBase : EnvelopeReceiverQueryBase
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int? EnvelopeId => Envelope.Id;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int? ReceiverId => Receiver.Id;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public override ReceiverQueryBase Receiver { get => base.Receiver; set => base.Receiver = value; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current status code.
|
||||
/// </summary>
|
||||
|
||||
@@ -23,15 +23,23 @@ public class SaveDocStatusCommandHandler : IRequestHandler<SaveDocStatusCommand,
|
||||
|
||||
private readonly IRepository<DocumentStatus> _repo;
|
||||
|
||||
private readonly IRepository<Envelope> _envRepo;
|
||||
|
||||
private readonly IRepository<Receiver> _rcvRepo;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="mapper"></param>
|
||||
/// <param name="repo"></param>
|
||||
public SaveDocStatusCommandHandler(IMapper mapper, IRepository<DocumentStatus> repo)
|
||||
/// <param name="rcvRepo"></param>
|
||||
/// <param name="envRepo"></param>
|
||||
public SaveDocStatusCommandHandler(IMapper mapper, IRepository<DocumentStatus> repo, IRepository<Receiver> rcvRepo, IRepository<Envelope> envRepo)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_repo = repo;
|
||||
_rcvRepo = rcvRepo;
|
||||
_envRepo = envRepo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,6 +53,12 @@ public class SaveDocStatusCommandHandler : IRequestHandler<SaveDocStatusCommand,
|
||||
// ceck if exists
|
||||
bool isExists = await _repo.ReadOnly().Where(request).AnyAsync(cancel);
|
||||
|
||||
var env = await _envRepo.ReadOnly().Where(request.Envelope).FirstAsync(cancel);
|
||||
var rcv = await _rcvRepo.ReadOnly().Where(request.Receiver).FirstAsync(cancel);
|
||||
|
||||
request.Envelope.Id = env.Id;
|
||||
request.Receiver.Id = rcv.Id;
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
var uReq = request.To<UpdateDocStatusCommand>();
|
||||
|
||||
@@ -14,7 +14,12 @@ public class MappingProfile : Profile
|
||||
/// </summary>
|
||||
public MappingProfile()
|
||||
{
|
||||
CreateMap<CreateDocStatusCommand, DocumentStatus>();
|
||||
CreateMap<UpdateDocStatusCommand, DocumentStatus>();
|
||||
CreateMap<CreateDocStatusCommand, DocumentStatus>()
|
||||
.ForMember(dest => dest.Envelope, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Receiver, opt => opt.Ignore());
|
||||
|
||||
CreateMap<UpdateDocStatusCommand, DocumentStatus>()
|
||||
.ForMember(dest => dest.Envelope, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Receiver, opt => opt.Ignore());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user