Exemplo n.º 1
0
        public async Task AddAsync(int?authorId, int?textId, string content)
        {
            var suggestion = new Suggestion(content, 0);

            if (authorId != null)
            {
                suggestion.SetAuthor(new User((int)authorId));
            }
            if (textId != null)
            {
                suggestion.SetText(new Text((int)textId));
            }

            await suggestionRepository.AddAsync(suggestion);
        }
Exemplo n.º 2
0
        public async Task <SuggestionResponse> SaveAsync(Suggestion suggestion)
        {
            if (_userRepository.FindById(suggestion.UserId) != null)
            {
                try
                {
                    await _suggestionRepository.AddAsync(suggestion);

                    await _unitOfWork.CompleteAsync();

                    return(new SuggestionResponse(suggestion));
                }
                catch (Exception ex)
                {
                    return(new SuggestionResponse($"An error ocurred while saving the Suggestion: {ex.Message}"));
                }
            }
            else
            {
                return(new SuggestionResponse($"The User with id {suggestion.UserId}, doesn't exist"));
            }
        }
Exemplo n.º 3
0
        public async Task <SuggestionVm> Handle(CreateSuggestion request, CancellationToken cancellationToken)
        {
            var suggestion = await _suggestionRepository.AddAsync(new Suggestion( request.Name, request.UserId, ECategory.Movie));

            return(suggestion.ToVm());
        }