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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
|
||||
|
||||
public class CreateEvaluationValidator : AbstractValidator<CreateEvaluationRequest>
|
||||
{
|
||||
public CreateEvaluationValidator()
|
||||
{
|
||||
RuleFor(x => x.EmployeeId)
|
||||
.NotEmpty().WithMessage("Employee is required");
|
||||
|
||||
RuleFor(x => x.Period)
|
||||
.NotEmpty().WithMessage("Evaluation Period is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.FinalScore)
|
||||
.NotEmpty().WithMessage("Final Score is required");
|
||||
|
||||
RuleFor(x => x.EvaluatorId)
|
||||
.NotEmpty().WithMessage("Evaluator is required");
|
||||
|
||||
RuleFor(x => x.EvaluationDate)
|
||||
.NotEmpty().WithMessage("Evaluation Date is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
|
||||
|
||||
public record DeleteEvaluationByIdRequest(string Id);
|
||||
|
||||
public record DeleteEvaluationByIdCommand(DeleteEvaluationByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteEvaluationByIdHandler : IRequestHandler<DeleteEvaluationByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteEvaluationByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteEvaluationByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Evaluation
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Evaluation.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
|
||||
|
||||
public class GetEvaluationByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? EmployeeId { get; set; }
|
||||
public string? EmployeeCode { get; set; }
|
||||
public string? EmployeeName { get; set; }
|
||||
public string? Period { get; set; }
|
||||
public string? FinalScore { get; set; }
|
||||
public string? Rating { get; set; }
|
||||
public string? EvaluatorId { get; set; }
|
||||
public string? EvaluatorCode { get; set; }
|
||||
public string? EvaluatorName { get; set; }
|
||||
public DateTime EvaluationDate { get; set; }
|
||||
public string? EvaluationNote { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetEvaluationByIdQuery(string Id) : IRequest<GetEvaluationByIdResponse?>;
|
||||
|
||||
public class GetEvaluationByIdHandler : IRequestHandler<GetEvaluationByIdQuery, GetEvaluationByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetEvaluationByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetEvaluationByIdResponse?> Handle(GetEvaluationByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Evaluation
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Evaluator)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetEvaluationByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
EmployeeId = x.EmployeeId,
|
||||
EmployeeCode = x.Employee != null ? x.Employee.Code : string.Empty,
|
||||
EmployeeName = x.Employee != null ? $"{x.Employee.FirstName} {x.Employee.LastName}" : string.Empty,
|
||||
Period = x.Period,
|
||||
FinalScore = x.FinalScore,
|
||||
Rating = x.Rating,
|
||||
EvaluatorId = x.EvaluatorId,
|
||||
EvaluatorCode = x.Evaluator != null ? x.Evaluator.Code : string.Empty,
|
||||
EvaluatorName = x.Evaluator != null ? $"{x.Evaluator.FirstName} {x.Evaluator.LastName}" : string.Empty,
|
||||
EvaluationDate = x.EvaluationDate,
|
||||
EvaluationNote = x.EvaluationNote,
|
||||
Status = x.Status,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
|
||||
|
||||
public class GetEvaluationListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? EmployeeId { get; set; }
|
||||
public string? EmployeeCode { get; set; }
|
||||
public string? EmployeeName { get; set; }
|
||||
public string? Period { get; set; }
|
||||
public string? FinalScore { get; set; }
|
||||
public string? Rating { get; set; }
|
||||
public string? EvaluatorName { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public DateTime EvaluationDate { get; set; }
|
||||
}
|
||||
|
||||
public record GetEvaluationListQuery() : IRequest<List<GetEvaluationListResponse>>;
|
||||
|
||||
public class GetEvaluationListHandler : IRequestHandler<GetEvaluationListQuery, List<GetEvaluationListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetEvaluationListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetEvaluationListResponse>> Handle(GetEvaluationListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Evaluation
|
||||
.AsNoTracking()
|
||||
.NotDeletedOnly()
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Evaluator)
|
||||
.OrderByDescending(x => x.EvaluationDate)
|
||||
.Select(x => new GetEvaluationListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
EmployeeId = x.EmployeeId,
|
||||
EmployeeCode = x.Employee != null ? x.Employee.Code : string.Empty,
|
||||
EmployeeName = x.Employee != null ? $"{x.Employee.FirstName} {x.Employee.LastName}" : string.Empty,
|
||||
Period = x.Period,
|
||||
FinalScore = x.FinalScore,
|
||||
Rating = x.Rating,
|
||||
EvaluatorName = x.Evaluator != null ? $"{x.Evaluator.FirstName} {x.Evaluator.LastName}" : string.Empty,
|
||||
Status = x.Status,
|
||||
EvaluationDate = x.EvaluationDate
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
|
||||
|
||||
public class UpdateEvaluationValidator : AbstractValidator<UpdateEvaluationRequest>
|
||||
{
|
||||
public UpdateEvaluationValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required for update");
|
||||
|
||||
RuleFor(x => x.EmployeeId)
|
||||
.NotEmpty().WithMessage("Employee is required");
|
||||
|
||||
RuleFor(x => x.Period)
|
||||
.NotEmpty().WithMessage("Evaluation Period is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.FinalScore)
|
||||
.NotEmpty().WithMessage("Final Score is required");
|
||||
|
||||
RuleFor(x => x.EvaluatorId)
|
||||
.NotEmpty().WithMessage("Evaluator is required");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user