MireaBackend/Application/Cqrs/Faculty/Commands/UpdateFaculty/UpdateFacultyCommandHandler.cs

20 lines
891 B
C#
Raw Normal View History

2024-01-25 17:39:07 +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.Faculty.Commands.UpdateFaculty;
public class UpdateFacultyCommandHandler(IFacultyDbContext dbContext) : IRequestHandler<UpdateFacultyCommand>
{
public async Task Handle(UpdateFacultyCommand request, CancellationToken cancellationToken)
{
var entity = await dbContext.Faculties.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Faculty), nameof(Domain.Schedule.Faculty.Id), request.Id);
entity.CampusId = request.CampusId;
await dbContext.SaveChangesAsync(cancellationToken);
}
}