Пример #1
0
        public async Task <IActionResult> CreateAsync(CommentViewModel comment)
        {
            if (!ModelState.IsValid)
            {
                var isReply  = !string.IsNullOrEmpty(comment.ParentId);
                var viewName = isReply ? nameof(ReplyAsync) : nameof(CreateAsync);

                if (isReply)
                {
                    await FillReplyModelAsync(comment);
                }

                return(PartialView(viewName, comment));
            }

            comment.Id = Guid.NewGuid().ToString();
            CommentViewModelHelper.SetupHtmlId(comment);

            var commentDto = _mapper.Map <CommentDto>(comment);

            commentDto.UserId = User?.GetId();
            await _commentServices.CreateAsync(commentDto);

            _logger.LogDebug($"Add new comment to game with key {comment.GameKey}");

            return(PartialView("DisplayComment", comment));
        }
Пример #2
0
        private async Task FillReplyModelAsync(CommentViewModel commentViewModel, bool isQuote = false)
        {
            var parent = await _commentServices.GetByIdAsync(commentViewModel.ParentId);

            commentViewModel.Parent    = _mapper.Map <CommentViewModel>(parent);
            commentViewModel.QuoteText = isQuote ? parent.Body : commentViewModel.QuoteText;
            commentViewModel.GameKey   = parent.GameKey;

            CommentViewModelHelper.SetupHtmlId(commentViewModel);
        }
        public async Task <DisplayCommentsViewModel> CreateAsync(CommentViewModel model)
        {
            var comments = await _commentServices.GetCommentsTreeByGameKeyAsync(model.GameKey);

            var commentViewModels = _mapper.Map <IEnumerable <CommentViewModel> >(comments);

            foreach (var viewModel in commentViewModels)
            {
                CommentViewModelHelper.SetupHtmlId(viewModel);
            }

            var displayCommentViewModel = new DisplayCommentsViewModel
            {
                Comment = new CommentViewModel {
                    GameKey = model.GameKey
                },
                Comments = commentViewModels
            };

            return(displayCommentViewModel);
        }