diff --git a/Application/Cqrs/TypeOfOccupation/Commands/UpdateTypeOfOccupation/UpdateTypeOfOccupationCommand.cs b/Application/Cqrs/TypeOfOccupation/Commands/UpdateTypeOfOccupation/UpdateTypeOfOccupationCommand.cs new file mode 100644 index 0000000..8950adf --- /dev/null +++ b/Application/Cqrs/TypeOfOccupation/Commands/UpdateTypeOfOccupation/UpdateTypeOfOccupationCommand.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.TypeOfOccupation.Commands.UpdateTypeOfOccupation; + +public class UpdateTypeOfOccupationCommand : IRequest +{ + public required int Id { get; set; } + public required string FullName { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/TypeOfOccupation/Commands/UpdateTypeOfOccupation/UpdateTypeOfOccupationCommandHandler.cs b/Application/Cqrs/TypeOfOccupation/Commands/UpdateTypeOfOccupation/UpdateTypeOfOccupationCommandHandler.cs new file mode 100644 index 0000000..ba0428b --- /dev/null +++ b/Application/Cqrs/TypeOfOccupation/Commands/UpdateTypeOfOccupation/UpdateTypeOfOccupationCommandHandler.cs @@ -0,0 +1,20 @@ +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.EntityFrameworkCore; +using Mirea.Api.DataAccess.Application.Common.Exceptions; +using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; + +namespace Mirea.Api.DataAccess.Application.Cqrs.TypeOfOccupation.Commands.UpdateTypeOfOccupation; + +public class UpdateTypeOfOccupationCommandHandler(ITypeOfOccupationDbContext dbContext) : IRequestHandler +{ + public async Task Handle(UpdateTypeOfOccupationCommand request, CancellationToken cancellationToken) + { + var entity = await dbContext.TypeOfOccupations.FirstOrDefaultAsync(t => t.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.TypeOfOccupation), nameof(Domain.Schedule.TypeOfOccupation.Id), request.Id); + + entity.FullName = request.FullName; + + await dbContext.SaveChangesAsync(cancellationToken); + } +} \ No newline at end of file