initial commit

This commit is contained in:
2026-07-21 14:08:10 +07:00
commit f7cf118326
533 changed files with 41762 additions and 0 deletions
@@ -0,0 +1,61 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
namespace Indotalent.Features.Performance.Promotion.Cqrs;
public class CreatePromotionRequest
{
public string EmployeeId { get; set; } = string.Empty;
public string FromGrade { get; set; } = string.Empty;
public string ToGrade { get; set; } = string.Empty;
public DateTime? EffectiveDate { get; set; }
public string PromotionNote { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
}
public class CreatePromotionResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
}
public record CreatePromotionCommand(CreatePromotionRequest Data) : IRequest<CreatePromotionResponse>;
public class CreatePromotionHandler : IRequestHandler<CreatePromotionCommand, CreatePromotionResponse>
{
private readonly AppDbContext _context;
public CreatePromotionHandler(AppDbContext context) => _context = context;
public async Task<CreatePromotionResponse> Handle(CreatePromotionCommand request, CancellationToken cancellationToken)
{
var entityName = nameof(Data.Entities.Promotion);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.Promotion
{
AutoNumber = autoNo,
EmployeeId = request.Data.EmployeeId,
FromGrade = request.Data.FromGrade,
ToGrade = request.Data.ToGrade,
EffectiveDate = request.Data.EffectiveDate,
PromotionNote = request.Data.PromotionNote,
Status = request.Data.Status
};
_context.Promotion.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreatePromotionResponse
{
Id = entity.Id,
AutoNumber = entity.AutoNumber
};
}
}
@@ -0,0 +1,14 @@
using FluentValidation;
namespace Indotalent.Features.Performance.Promotion.Cqrs;
public class CreatePromotionValidator : AbstractValidator<CreatePromotionRequest>
{
public CreatePromotionValidator()
{
RuleFor(x => x.EmployeeId).NotEmpty().WithMessage("Employee is required");
RuleFor(x => x.ToGrade).NotEmpty().WithMessage("Target Grade is required");
RuleFor(x => x.EffectiveDate).NotEmpty().WithMessage("Effective Date is required");
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Performance.Promotion.Cqrs;
public record DeletePromotionByIdRequest(string Id);
public record DeletePromotionByIdCommand(DeletePromotionByIdRequest Data) : IRequest<bool>;
public class DeletePromotionByIdHandler : IRequestHandler<DeletePromotionByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeletePromotionByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeletePromotionByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Promotion
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.Promotion.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,58 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Performance.Promotion.Cqrs;
public class GetPromotionByIdResponse
{
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? FromGrade { get; set; }
public string? ToGrade { get; set; }
public DateTime? EffectiveDate { get; set; }
public string? PromotionNote { 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 GetPromotionByIdQuery(string Id) : IRequest<GetPromotionByIdResponse?>;
public class GetPromotionByIdHandler : IRequestHandler<GetPromotionByIdQuery, GetPromotionByIdResponse?>
{
private readonly AppDbContext _context;
public GetPromotionByIdHandler(AppDbContext context) => _context = context;
public async Task<GetPromotionByIdResponse?> Handle(GetPromotionByIdQuery request, CancellationToken cancellationToken)
{
return await _context.Promotion
.AsNoTracking()
.Include(x => x.Employee)
.Where(x => x.Id == request.Id)
.Select(x => new GetPromotionByIdResponse
{
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,
FromGrade = x.FromGrade,
ToGrade = x.ToGrade,
EffectiveDate = x.EffectiveDate,
PromotionNote = x.PromotionNote,
Status = x.Status,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,50 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Performance.Promotion.Cqrs;
public class GetPromotionListResponse
{
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? FromGrade { get; set; }
public string? ToGrade { get; set; }
public DateTime? EffectiveDate { get; set; }
public string? Status { get; set; }
}
public record GetPromotionListQuery() : IRequest<List<GetPromotionListResponse>>;
public class GetPromotionListHandler : IRequestHandler<GetPromotionListQuery, List<GetPromotionListResponse>>
{
private readonly AppDbContext _context;
public GetPromotionListHandler(AppDbContext context) => _context = context;
public async Task<List<GetPromotionListResponse>> Handle(GetPromotionListQuery request, CancellationToken cancellationToken)
{
return await _context.Promotion
.AsNoTracking()
.NotDeletedOnly()
.Include(x => x.Employee)
.OrderByDescending(x => x.CreatedAt)
.Select(x => new GetPromotionListResponse
{
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,
FromGrade = x.FromGrade,
ToGrade = x.ToGrade,
EffectiveDate = x.EffectiveDate,
Status = x.Status
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,57 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Performance.Promotion.Cqrs;
public class UpdatePromotionRequest : CreatePromotionRequest
{
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 UpdatePromotionResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdatePromotionCommand(UpdatePromotionRequest Data) : IRequest<UpdatePromotionResponse>;
public class UpdatePromotionHandler : IRequestHandler<UpdatePromotionCommand, UpdatePromotionResponse>
{
private readonly AppDbContext _context;
public UpdatePromotionHandler(AppDbContext context) => _context = context;
public async Task<UpdatePromotionResponse> Handle(UpdatePromotionCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Promotion
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdatePromotionResponse { Id = request.Data.Id, Success = false };
}
entity.EmployeeId = request.Data.EmployeeId;
entity.FromGrade = request.Data.FromGrade;
entity.ToGrade = request.Data.ToGrade;
entity.EffectiveDate = request.Data.EffectiveDate;
entity.PromotionNote = request.Data.PromotionNote;
entity.Status = request.Data.Status;
await _context.SaveChangesAsync(cancellationToken);
return new UpdatePromotionResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,12 @@
using FluentValidation;
using Indotalent.Features.Performance.Promotion.Cqrs;
public class UpdatePromotionValidator : AbstractValidator<UpdatePromotionRequest>
{
public UpdatePromotionValidator()
{
RuleFor(x => x.Id).NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.EmployeeId).NotEmpty().WithMessage("Employee is required");
RuleFor(x => x.ToGrade).NotEmpty().WithMessage("Target Grade is required");
}
}