public async Task HandleAsync(AddTrip command)
        {
            if (await _tripRepository.ExistsAsync(command.TripId))
            {
                throw new TripAlreadyExistsException(command.TripId);
            }

            var trip = Core.Entities.Trip.Create(command.TripId, command.Destination, command.Date,
                                                 command.DifficultyLevel);
            await _tripRepository.AddAsync(trip);

            await _eventProcessor.ProcessAsync(trip.Events);
        }
        public async Task <TripResponse> SaveAsync(Trip trip)
        {
            try
            {
                trip.Neutral();
                await _tripRepository.AddAsync(trip);

                await _unitOfWork.CompleteAsync();

                return(new TripResponse(trip));
            }
            catch (Exception ex)
            {
                return(new TripResponse($"An error ocurred while saving this trip: {ex.Message}"));
            }
        }
Exemplo n.º 3
0
        public async Task <TripViewModel> Handle(CreateTripCommand request, CancellationToken cancellationToken)
        {
            var tripLegs = new List <(string route, decimal revenue)>();

            foreach (var tuple in request.TripLegs)
            {
                tripLegs.Add((tuple.Route, tuple.Revenue));
            }

            var trip = new Trip(request.TripDate, request.BusId, request.DriverId, request.ConductorId, tripLegs);

            var entity = await _tripRepository.AddAsync(trip);

            await _tripRepository.UnitOfWork.SaveEntitiesAsync();

            return(MapTripToTripViewModel(entity));
        }