fix: delete a non-existent table
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m22s
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m22s
This commit is contained in:
parent
84c6123caf
commit
2c3e02b2de
@ -1,12 +0,0 @@
|
|||||||
using MediatR;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Day.Commands.CreateDay;
|
|
||||||
|
|
||||||
public class CreateDayCommand : IRequest<int>
|
|
||||||
{
|
|
||||||
public required DayOfWeek Index { get; set; }
|
|
||||||
public required int PairNumber { get; set; }
|
|
||||||
public required int LessonId { get; set; }
|
|
||||||
public required int GroupId { get; set; }
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
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.CreateDay;
|
|
||||||
|
|
||||||
public class CreateDayCommandHandler(IDayDbContext dbContext) : IRequestHandler<CreateDayCommand, int>
|
|
||||||
{
|
|
||||||
public async Task<int> Handle(CreateDayCommand request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var entity = await dbContext.Days
|
|
||||||
.FirstOrDefaultAsync(d =>
|
|
||||||
d.LessonId == request.LessonId
|
|
||||||
&& d.PairNumber == request.PairNumber
|
|
||||||
&& d.GroupId == request.GroupId
|
|
||||||
&& d.Index == request.Index,
|
|
||||||
cancellationToken: cancellationToken);
|
|
||||||
|
|
||||||
if (entity != null)
|
|
||||||
throw new RecordExistException(typeof(Domain.Schedule.Day), entity.Id);
|
|
||||||
|
|
||||||
var day = new Domain.Schedule.Day()
|
|
||||||
{
|
|
||||||
Index = request.Index,
|
|
||||||
PairNumber = request.PairNumber,
|
|
||||||
GroupId = request.GroupId,
|
|
||||||
LessonId = request.LessonId
|
|
||||||
};
|
|
||||||
|
|
||||||
var result = await dbContext.Days.AddAsync(day, cancellationToken);
|
|
||||||
await dbContext.SaveChangesAsync(cancellationToken);
|
|
||||||
|
|
||||||
return result.Entity.Id;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
using MediatR;
|
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Day.Commands.DeleteDay;
|
|
||||||
|
|
||||||
public class DeleteDayCommand : IRequest
|
|
||||||
{
|
|
||||||
public required int Id { get; set; }
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user