initial commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
|
||||
|
||||
public class UpdateEvaluationRequest : CreateEvaluationRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? EmployeeCode { get; set; }
|
||||
public string? EmployeeName { get; set; }
|
||||
public string? EvaluatorCode { get; set; }
|
||||
public string? EvaluatorName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateEvaluationResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateEvaluationCommand(UpdateEvaluationRequest Data) : IRequest<UpdateEvaluationResponse>;
|
||||
|
||||
public class UpdateEvaluationHandler : IRequestHandler<UpdateEvaluationCommand, UpdateEvaluationResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateEvaluationHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateEvaluationResponse> Handle(UpdateEvaluationCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Evaluation
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateEvaluationResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.EmployeeId = request.Data.EmployeeId;
|
||||
entity.Period = request.Data.Period;
|
||||
entity.FinalScore = request.Data.FinalScore;
|
||||
entity.Rating = request.Data.Rating;
|
||||
entity.EvaluatorId = request.Data.EvaluatorId;
|
||||
entity.EvaluationDate = request.Data.EvaluationDate;
|
||||
entity.EvaluationNote = request.Data.EvaluationNote;
|
||||
entity.Status = request.Data.Status;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateEvaluationResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user