public void Setup()
        {
            var validCommand = new CommentASuggestionCommand
            {
                SuggestionId = Guid.NewGuid(),
                UserId       = "valid user id",
                Comment      = "any value"
            };

            _repository        = new SuggestionRepository(_dbContext);
            _validationContext = new CommentASuggestionValidationContext(validCommand, _repository);
        }
Example #2
0
        public async Task <Suggestion> Handle(CommentASuggestionCommand commentASuggestion, CancellationToken cancellationToken = default)
        {
            var validationContext = new CommentASuggestionValidationContext(commentASuggestion, _repository);

            _commentValidator.Validate(validationContext);

            var suggestionComment = _mapper.Map <SuggestionComment>(commentASuggestion);
            var suggestion        = _repository.AddComment(commentASuggestion.SuggestionId, suggestionComment);

            suggestionComment.Suggestion = suggestion;

            await _dbContext.SaveChangesAsync();

            var createANotificationCommand = _mapper.Map <CreateANotificationCommand>(suggestionComment);

            createANotificationCommand.ConcernedUserIds = new[] { suggestion.CreatedBy };

            await _mediator.Send(createANotificationCommand);

            return(suggestion);
        }
Example #3
0
 public CommentASuggestionValidationContext(CommentASuggestionCommand command, ISuggestionRepository repository)
 {
     Command = command;
     RepositoryValidationContext = new CommonSuggestionRepositoryValidationContext(repository, Command.SuggestionId);
 }