initial commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Leave.LeaveRequest.Cqrs;
|
||||
|
||||
public class UpdateLeaveRequestRequest : CreateLeaveRequestRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? EmployeeName { get; set; }
|
||||
public string? LeaveType { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
public string? RejectReason { get; set; }
|
||||
public string? ApproverId { get; set; }
|
||||
public DateTime? ActionDate { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateLeaveRequestResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateLeaveRequestCommand(UpdateLeaveRequestRequest Data) : IRequest<UpdateLeaveRequestResponse>;
|
||||
|
||||
public class UpdateLeaveRequestHandler : IRequestHandler<UpdateLeaveRequestCommand, UpdateLeaveRequestResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateLeaveRequestHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateLeaveRequestResponse> Handle(UpdateLeaveRequestCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeaveRequest
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateLeaveRequestResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.EmployeeId = request.Data.EmployeeId;
|
||||
entity.LeaveCategoryId = request.Data.LeaveCategoryId;
|
||||
entity.StartDate = request.Data.StartDate;
|
||||
entity.EndDate = request.Data.EndDate;
|
||||
entity.Days = request.Data.Days;
|
||||
entity.Reason = request.Data.Reason;
|
||||
entity.Status = request.Data.Status;
|
||||
entity.AttachmentPath = request.Data.AttachmentPath;
|
||||
entity.RejectReason = request.Data.RejectReason;
|
||||
entity.ApproverId = request.Data.ApproverId;
|
||||
entity.ActionDate = request.Data.ActionDate;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateLeaveRequestResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user