using AutobusApi.Application.Common.Exceptions; using AutobusApi.Application.Common.Interfaces; using MediatR; namespace AutobusApi.Application.Companies.Commands.UpdateCompany; public class UpdateCompanyCommandHandler : IRequestHandler { private readonly IApplicationDbContext _dbContext; public UpdateCompanyCommandHandler(IApplicationDbContext dbContext) { _dbContext = dbContext; } public async Task Handle( UpdateCompanyCommand request, CancellationToken cancellationToken) { var company = await _dbContext.Companies .FindAsync(new object[] { request.Id }, cancellationToken); if (company == null) { throw new NotFoundException(); } company.Name = request.Name; company.LegalAddress = request.LegalAddress; company.ContactEmail = request.ContactEmail; company.ContactPhoneNumber = request.ContactPhoneNumber; await _dbContext.SaveChangesAsync(cancellationToken); } }