54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Performance.Transfer.Cqrs;
|
|
|
|
public class UpdateTransferRequest : CreateTransferRequest
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? AutoNumber { get; set; }
|
|
public string? EmployeeName { get; set; }
|
|
public DateTimeOffset? CreatedAt { get; set; }
|
|
public string? CreatedBy { get; set; }
|
|
public DateTimeOffset? UpdatedAt { get; set; }
|
|
public string? UpdatedBy { get; set; }
|
|
}
|
|
|
|
public class UpdateTransferResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public bool Success { get; set; }
|
|
}
|
|
|
|
public record UpdateTransferCommand(UpdateTransferRequest Data) : IRequest<UpdateTransferResponse>;
|
|
|
|
public class UpdateTransferHandler : IRequestHandler<UpdateTransferCommand, UpdateTransferResponse>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public UpdateTransferHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<UpdateTransferResponse> Handle(UpdateTransferCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var entity = await _context.Transfer
|
|
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
|
|
|
if (entity == null) return new UpdateTransferResponse { Success = false };
|
|
|
|
entity.EmployeeId = request.Data.EmployeeId;
|
|
entity.FromBranchId = request.Data.FromBranchId;
|
|
entity.FromDepartmentId = request.Data.FromDepartmentId;
|
|
entity.FromDesignationId = request.Data.FromDesignationId;
|
|
entity.ToBranchId = request.Data.ToBranchId;
|
|
entity.ToDepartmentId = request.Data.ToDepartmentId;
|
|
entity.ToDesignationId = request.Data.ToDesignationId;
|
|
entity.TransferDate = request.Data.TransferDate;
|
|
entity.TransferNote = request.Data.TransferNote;
|
|
entity.Status = request.Data.Status;
|
|
|
|
await _context.SaveChangesAsync(cancellationToken);
|
|
|
|
return new UpdateTransferResponse { Id = entity.Id, Success = true };
|
|
}
|
|
} |