feat: add a day command
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m24s

This commit is contained in:
2024-01-25 17:53:22 +03:00
parent c82b29e90e
commit 2bb7573ca0
4 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,8 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Day.Commands.DeleteDay;
public class DeleteDayCommand : IRequest
{
public required int Id { get; set; }
}

View File

@ -0,0 +1,20 @@
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);
}
}