initial commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
|
||||
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
|
||||
|
||||
public class CreateEvaluationRequest
|
||||
{
|
||||
public string EmployeeId { get; set; } = string.Empty;
|
||||
public string Period { get; set; } = string.Empty;
|
||||
public string FinalScore { get; set; } = string.Empty;
|
||||
public string Rating { get; set; } = string.Empty;
|
||||
public string EvaluatorId { get; set; } = string.Empty;
|
||||
public DateTime EvaluationDate { get; set; }
|
||||
public string EvaluationNote { get; set; } = string.Empty;
|
||||
public string Status { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class CreateEvaluationResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
}
|
||||
|
||||
public record CreateEvaluationCommand(CreateEvaluationRequest Data) : IRequest<CreateEvaluationResponse>;
|
||||
|
||||
public class CreateEvaluationHandler : IRequestHandler<CreateEvaluationCommand, CreateEvaluationResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateEvaluationHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateEvaluationResponse> Handle(CreateEvaluationCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.Evaluation);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Evaluation
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
EmployeeId = request.Data.EmployeeId,
|
||||
Period = request.Data.Period,
|
||||
FinalScore = request.Data.FinalScore,
|
||||
Rating = request.Data.Rating,
|
||||
EvaluatorId = request.Data.EvaluatorId,
|
||||
EvaluationDate = request.Data.EvaluationDate,
|
||||
EvaluationNote = request.Data.EvaluationNote,
|
||||
Status = request.Data.Status
|
||||
};
|
||||
|
||||
_context.Evaluation.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateEvaluationResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
AutoNumber = entity.AutoNumber
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user