using AutobusApi.Application.Common.Exceptions; using AutobusApi.Application.Common.Interfaces; using AutobusApi.Domain.Enums; using MediatR; namespace AutobusApi.Application.Addresses.Commands.UpdateAddress; public class UpdateAddressCommandHandler : IRequestHandler { private readonly IApplicationDbContext _dbContext; public UpdateAddressCommandHandler(IApplicationDbContext dbContext) { _dbContext = dbContext; } public async Task Handle( UpdateAddressCommand request, CancellationToken cancellationToken) { var address = await _dbContext.Addresses .FindAsync(new object[] { request.Id }, cancellationToken); if (address == null) { throw new NotFoundException(); } address.Name = request.Name; address.CityId = request.CityId; // TODO: Fix abstraction problems // address.Location.Latitude = request.Latitude; // address.Location.Longitude = request.Longitude; address.VehicleType = Enum.Parse(request.VehicleType); await _dbContext.SaveChangesAsync(cancellationToken); } }