feat: add a type of occupation update
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 2m41s

This commit is contained in:
Polianin Nikita 2024-01-21 22:53:52 +03:00
parent af7e370494
commit 9b0e5a3f15
2 changed files with 29 additions and 0 deletions

View File

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

View File

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