MireaBackend/Application/Cqrs/Professor/Commands/UpdateProfessor/UpdateProfessorCommandHandler.cs

20 lines
906 B
C#
Raw Normal View History

2024-01-21 23:55:47 +03:00
using System.Threading;
using System.Threading.Tasks;
using MediatR;
2024-01-21 23:17:10 +03:00
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
2024-01-21 23:55:47 +03:00
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Commands.UpdateProfessor;
2024-01-21 23:17:10 +03:00
public class UpdateProfessorCommandHandler(IProfessorDbContext dbContext) : IRequestHandler<UpdateProfessorCommand>
{
public async Task Handle(UpdateProfessorCommand request, CancellationToken cancellationToken)
{
var entity = await dbContext.Professors.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Professor), nameof(Domain.Schedule.Professor.Id), request.Id);
entity.AltName = request.AltName;
await dbContext.SaveChangesAsync(cancellationToken);
}
}