Exemple #1
0
        protected override async Task Handle(AddTripParticipantCommand request, CancellationToken cancellationToken)
        {
            if (await _userRepository.GetAsync(x => x.Id == request.TripParticipant.UserId) == null)
            {
                throw new EntityNotFoundException($"User with Id {request.TripParticipant.UserId} doesn't exist.");
            }

            var trip = await _tripsRepository.GetDetailsByIdAsync(request.TripParticipant.TripId);

            if (trip == null)
            {
                throw new EntityNotFoundException($"Trip with Id {request.TripParticipant.UserId} doesn't exist.");
            }

            if (trip.TripParticipants.SingleOrDefault(x => x.UserId == request.TripParticipant.UserId) != null ||
                trip.AuthorId == request.TripParticipant.UserId)
            {
                throw new UniqueConstraintViolatedException($"User with Id {request.TripParticipant.UserId} already participates in trip with Id {request.TripParticipant.TripId}.");
            }
            await _tripParticipantRepository.AddAsync(request.TripParticipant);
        }
 public Task <Trip> Handle(GetTripDetailsQuery request, CancellationToken cancellationToken)
 {
     return(_tripsRepository.GetDetailsByIdAsync(request.TripId));
 }