feat: add a professor update
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m57s
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m57s
This commit is contained in:
parent
654065f016
commit
dbc8f7c68c
@ -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; }
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user