Exemple #1
0
        public Task <Unit> Handle(AcceptTrainingRequest request, CancellationToken cancellationToken)
        {
            _trainerRepo.AcceptTrainingRequest(request.RequestId);

            var requestEntity = _requestRepo.Get(request.RequestId);

            var user    = requestEntity.User;
            var trainer = requestEntity.Trainer;

            _bus.Publish(new TrainingRequestAccepted
            {
                TrainerEmail     = trainer.Email,
                TrainerFirstName = trainer.FirstName,
                TrainerLastName  = trainer.LastName,
                UserFirstName    = user.FirstName,
                UserLastName     = user.LastName,
                UserUsername     = user.Username
            });

            return(Unit.Task);
        }
Exemple #2
0
        public Task <Unit> Handle(SendTrainingRequestRequest request, CancellationToken cancellationToken)
        {
            var user = _userRepo.Get(request.UserId);

            if (user == null)
            {
                throw new EntityNotFoundException(request.UserId, "User");
            }

            var trainer = _trainerRepo.Get(request.TrainerId);

            if (trainer == null)
            {
                throw new EntityNotFoundException(request.TrainerId, "Trainer");
            }

            if (_requestRepo.Get(r => r.TrainerId == request.TrainerId && r.UserId == request.UserId && r.IsActive).Any())
            {
                throw new EntityAlreadyExistsException("Request to this trainer has already been sent and is waiting for response.");
            }

            _requestRepo.Add(new TrainingRequest
            {
                TrainerId = request.TrainerId,
                UserId    = request.UserId
            });

            _eventBus.Publish(new TrainingRequestRecieved
            {
                TrainerEmail     = trainer.Email,
                TrainerFirstName = trainer.FirstName,
                TrainerLastName  = trainer.LastName,
                UserFirstName    = user.FirstName,
                UserLastName     = user.LastName,
                UserUsername     = user.Username
            });

            return(Unit.Task);
        }