Files
minattest/backend/src/MinAttest.Application/Features/Employers/Commands/DeleteEmployerUserCommand.cs
T
Stein Helge Riise ede31fbb7e Initial import
2025-11-17 08:32:46 +01:00

21 lines
808 B
C#

using MediatR;
using Microsoft.EntityFrameworkCore;
using MinAttest.Application.Abstractions;
namespace MinAttest.Application.Features.Employers.Commands;
public record DeleteEmployerUserCommand(Guid EmployerId, Guid UserId) : IRequest<bool>;
public class DeleteEmployerUserCommandHandler(IAppDbContext db) : IRequestHandler<DeleteEmployerUserCommand, bool>
{
public async Task<bool> Handle(DeleteEmployerUserCommand request, CancellationToken cancellationToken)
{
var user = await db.EmployerUsers.FirstOrDefaultAsync(u => u.Id == request.UserId && u.EmployerId == request.EmployerId, cancellationToken);
if (user is null) return false;
db.EmployerUsers.Remove(user);
await db.SaveChangesAsync(cancellationToken);
return true;
}
}