diff --git a/Application/Cqrs/Professor/Commands/UpdateTypeOfOccupation/UpdateProfessorCommand.cs b/Application/Cqrs/Professor/Commands/UpdateTypeOfOccupation/UpdateProfessorCommand.cs new file mode 100644 index 0000000..0029701 --- /dev/null +++ b/Application/Cqrs/Professor/Commands/UpdateTypeOfOccupation/UpdateProfessorCommand.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Commands.UpdateTypeOfOccupation; + +public class UpdateProfessorCommand : IRequest +{ + public required int Id { get; set; } + public required string AltName { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Professor/Commands/UpdateTypeOfOccupation/UpdateProfessorCommandHandler.cs b/Application/Cqrs/Professor/Commands/UpdateTypeOfOccupation/UpdateProfessorCommandHandler.cs new file mode 100644 index 0000000..1d04355 --- /dev/null +++ b/Application/Cqrs/Professor/Commands/UpdateTypeOfOccupation/UpdateProfessorCommandHandler.cs @@ -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.Professor.Commands.UpdateTypeOfOccupation; + +public class UpdateProfessorCommandHandler(IProfessorDbContext dbContext) : IRequestHandler +{ + 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); + } +} \ No newline at end of file