public async Task <Ride> Handle(AddRideCommand request, CancellationToken cancellationToken) { IdGenerator rideIdGenerator = new(IdGeneratorType.Ride); var rideId = rideIdGenerator.CreateId(); var ride = new Ride(new RideId(rideId), request.OwnerId, request.GroupId, request.Date, request.Price, request.Location ?? throw new ApiProblemDetailsException("Ride must have a destination", StatusCodes.Status400BadRequest), request.RideDirection, request.Stops?.Select(x => new Stop(x.ParticipantId, new Location(x.Location.Longitude, x.Location.Latitude), new RideId(rideId))) .ToList() ?? new List <Stop>(), request.SeatsLimit, new List <RideRequest>()); await _rideRepository.AddAsync(ride, cancellationToken).ConfigureAwait(false); try { await _unitOfWork.SaveAsync(cancellationToken).ConfigureAwait(false); } catch (SqlException ex) { throw new ApiException(ex); } return(ride); }
public async Task <IActionResult> AddRide([FromBody] Ride ride) { await rideRepository.AddAsync(ride); await rideRepository.SaveChangesAsync(); return(Ok()); }