using AutobusApi.Application.Common.Exceptions; using AutobusApi.Application.Common.Interfaces; using MediatR; namespace AutobusApi.Application.Buses.Commands.UpdateBus; public class UpdateBusCommandHandler : IRequestHandler { private readonly IApplicationDbContext _dbContext; public UpdateBusCommandHandler(IApplicationDbContext dbContext) { _dbContext = dbContext; } public async Task Handle( UpdateBusCommand request, CancellationToken cancellationToken) { var bus = await _dbContext.Buses .FindAsync(new object[] { request.Id }, cancellationToken); if (bus == null) { throw new NotFoundException(); } bus.CompanyId = request.CompanyId; bus.Number = request.Number; bus.Model = request.Model; bus.Capacity = request.Capacity; bus.HasClimateControl = request.HasClimateControl; bus.HasWiFi = request.HasWiFi; bus.HasMultimedia = request.HasMultimedia; bus.HasWC = request.HasWC; bus.HasOutlets = request.HasOutlets; await _dbContext.SaveChangesAsync(cancellationToken); } }