feat: add a professor update
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m57s

This commit is contained in:
Polianin Nikita 2024-01-21 23:17:10 +03:00
parent 654065f016
commit dbc8f7c68c
2 changed files with 29 additions and 0 deletions

View File

@ -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; }
}

View File

@ -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<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);
}
}