MireaBackend/Application/Cqrs/Group/Commands/UpdateGroup/UpdateGroupCommandHandler.cs

20 lines
874 B
C#
Raw Permalink Normal View History

2024-01-25 17:35:15 +03:00
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.Group.Commands.UpdateGroup;
public class UpdateGroupCommandHandler(IGroupDbContext dbContext) : IRequestHandler<UpdateGroupCommand>
{
public async Task Handle(UpdateGroupCommand request, CancellationToken cancellationToken)
{
var entity = await dbContext.Groups.FirstOrDefaultAsync(g => g.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Group), nameof(Domain.Schedule.Group.Id), request.Id);
entity.FacultyId = request.FacultyId;
await dbContext.SaveChangesAsync(cancellationToken);
}
}