using AutobusApi.Application.Common.Interfaces; using AutobusApi.Domain.Entities; using AutobusApi.Domain.Enums; using MediatR; namespace AutobusApi.Application.Addresses.Commands.CreateAddress; public class CreateAddressCommandHandler : IRequestHandler { private readonly IApplicationDbContext _dbContext; public CreateAddressCommandHandler(IApplicationDbContext dbContext) { _dbContext = dbContext; } public async Task Handle( CreateAddressCommand request, CancellationToken cancellationToken) { var address = new Address(); 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); _dbContext.Addresses.Add(address); await _dbContext.SaveChangesAsync(cancellationToken); return address.Id; } }