Пример #1
0
 public ActionResult NewComment( CommentViewModel model )
 {
     if (ModelState.IsValid)
     {
         GameDTO game = _gameService.GetGameByKey(model.GameKey);
         _commentService.AddCommentToGame(Mapper.Map<CommentViewModel, CommentDTO>(model), game);
         return RedirectToAction("Comments", new { key = model.GameKey });
     }
     var Comments = _commentService.CommentsAttachedToGame(model.GameKey)
         .Select(Mapper.Map<CommentDTO, CommentViewModel>)
         .ToList();
     GameCommentsViewModel gameComments = new GameCommentsViewModel {Comments = Comments, CommentToAdd = model};
     return View("Comments", gameComments);
 }
Пример #2
0
        public ViewResult Comments(string key)
        {
            GameCommentsViewModel model = new GameCommentsViewModel()
            {
                CommentToAdd = new CommentViewModel() { GameKey = key }
            };

            var Comments =
                _commentService.CommentsAttachedToGame(key)
                    .Select(Mapper.Map<CommentDTO, CommentViewModel>)
                    .ToList();
            Comments.ForEach( c => c.GameKey = key );
            List<CommentViewModel> commentsTree = new List<CommentViewModel>(Comments);
            foreach (CommentViewModel comment in Comments)
            {
                commentsTree = GetCommentTree(comment.ChildComments, commentsTree).ToList();
            }
            foreach (var comment in commentsTree)
            {
                if (comment.ChildComments != null)
                    AddParrentForQuote(comment.ChildComments, comment);
            }
            model.Comments = commentsTree;
            return View(model);
        }