initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Organization.Designation.Cqrs;
|
||||
|
||||
public record DeleteDesignationByIdRequest(string Id);
|
||||
|
||||
public record DeleteDesignationByIdCommand(DeleteDesignationByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteDesignationByIdHandler : IRequestHandler<DeleteDesignationByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteDesignationByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteDesignationByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Designation
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Designation.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user