feat: add a day command
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m24s
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m24s
This commit is contained in:
@ -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; }
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user