initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Performance.Appraisal.Cqrs;
|
||||
|
||||
public class UpdateAppraisalRequest : CreateAppraisalRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? EmployeeCode { 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 UpdateAppraisalResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateAppraisalCommand(UpdateAppraisalRequest Data) : IRequest<UpdateAppraisalResponse>;
|
||||
|
||||
public class UpdateAppraisalHandler : IRequestHandler<UpdateAppraisalCommand, UpdateAppraisalResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateAppraisalHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateAppraisalResponse> Handle(UpdateAppraisalCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Appraisal
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateAppraisalResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.EmployeeId = request.Data.EmployeeId;
|
||||
entity.LastRating = request.Data.LastRating;
|
||||
entity.CurrentSalary = request.Data.CurrentSalary;
|
||||
entity.IncrementPercentage = request.Data.IncrementPercentage;
|
||||
entity.NewSalary = request.Data.NewSalary;
|
||||
entity.AppraisalType = request.Data.AppraisalType;
|
||||
entity.EffectiveDate = request.Data.EffectiveDate;
|
||||
entity.AppraisalNote = request.Data.AppraisalNote;
|
||||
entity.Status = request.Data.Status;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateAppraisalResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user