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