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 CreateEmployeeIncomeRequest
|
||||
{
|
||||
public string? EmployeeId { get; set; }
|
||||
public string? IncomeId { get; set; }
|
||||
public decimal Amount { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
|
||||
public class CreateEmployeeIncomeResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
}
|
||||
|
||||
public record CreateEmployeeIncomeCommand(CreateEmployeeIncomeRequest Data) : IRequest<CreateEmployeeIncomeResponse>;
|
||||
|
||||
public class CreateEmployeeIncomeHandler : IRequestHandler<CreateEmployeeIncomeCommand, CreateEmployeeIncomeResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public CreateEmployeeIncomeHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateEmployeeIncomeResponse> Handle(CreateEmployeeIncomeCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.EmployeeIncome);
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"EINC/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.EmployeeIncome
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
EmployeeId = request.Data.EmployeeId,
|
||||
IncomeId = request.Data.IncomeId,
|
||||
Amount = request.Data.Amount,
|
||||
Description = request.Data.Description,
|
||||
IsActive = request.Data.IsActive
|
||||
};
|
||||
|
||||
_context.EmployeeIncome.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateEmployeeIncomeResponse { Id = entity.Id };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user