using AutobusApi.Application.Common.Exceptions; using AutobusApi.Application.Common.Interfaces; using MediatR; namespace AutobusApi.Application.Countries.Commands.UpdateCountry; public class UpdateCountryCommandHandler : IRequestHandler { private readonly IApplicationDbContext _dbContext; public UpdateCountryCommandHandler(IApplicationDbContext dbContext) { _dbContext = dbContext; } public async Task Handle( UpdateCountryCommand request, CancellationToken cancellationToken) { var country = await _dbContext.Countries .FindAsync(new object[] { request.Id }, cancellationToken); if (country == null) { throw new NotFoundException(); } country.Name = request.Name; await _dbContext.SaveChangesAsync(cancellationToken); } }