initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Organization.Employee.Cqrs;
|
||||
|
||||
public class UpdateEmployeeDeductionRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? DeductionId { get; set; }
|
||||
public decimal Amount { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateEmployeeDeductionResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateEmployeeDeductionCommand(UpdateEmployeeDeductionRequest Data) : IRequest<UpdateEmployeeDeductionResponse>;
|
||||
|
||||
public class UpdateEmployeeDeductionHandler : IRequestHandler<UpdateEmployeeDeductionCommand, UpdateEmployeeDeductionResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public UpdateEmployeeDeductionHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateEmployeeDeductionResponse> Handle(UpdateEmployeeDeductionCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.EmployeeDeduction
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) throw new NotFoundException("EmployeeDeduction", request.Data.Id ?? string.Empty);
|
||||
|
||||
entity.DeductionId = request.Data.DeductionId;
|
||||
entity.Amount = request.Data.Amount;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.IsActive = request.Data.IsActive;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateEmployeeDeductionResponse { Id = entity.Id };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user