Polianin Nikita
2bb7573ca0
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m24s
20 lines
860 B
C#
20 lines
860 B
C#
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Mirea.Api.DataAccess.Application.Common.Exceptions;
|
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Day.Commands.DeleteDay;
|
|
|
|
public class DeleteDayCommandHandler(ICampusDbContext dbContext) : IRequestHandler<DeleteDayCommand>
|
|
{
|
|
public async Task Handle(DeleteDayCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var entity = await dbContext.Campuses.FirstOrDefaultAsync(d => d.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Day), nameof(Domain.Schedule.Day.Id), request.Id);
|
|
|
|
dbContext.Campuses.Remove(entity);
|
|
|
|
await dbContext.SaveChangesAsync(cancellationToken);
|
|
}
|
|
} |