initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Organization.Employee.Cqrs;
|
||||
|
||||
public class CreateEmployeeDeductionRequest
|
||||
{
|
||||
public string? EmployeeId { get; set; }
|
||||
public string? DeductionId { get; set; }
|
||||
public decimal Amount { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
|
||||
public class CreateEmployeeDeductionResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
}
|
||||
|
||||
public record CreateEmployeeDeductionCommand(CreateEmployeeDeductionRequest Data) : IRequest<CreateEmployeeDeductionResponse>;
|
||||
|
||||
public class CreateEmployeeDeductionHandler : IRequestHandler<CreateEmployeeDeductionCommand, CreateEmployeeDeductionResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public CreateEmployeeDeductionHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateEmployeeDeductionResponse> Handle(CreateEmployeeDeductionCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.EmployeeDeduction);
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"EDED/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.EmployeeDeduction
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
EmployeeId = request.Data.EmployeeId,
|
||||
DeductionId = request.Data.DeductionId,
|
||||
Amount = request.Data.Amount,
|
||||
Description = request.Data.Description,
|
||||
IsActive = request.Data.IsActive
|
||||
};
|
||||
|
||||
_context.EmployeeDeduction.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateEmployeeDeductionResponse { Id = entity.Id };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user