public CommentsViewInfo GetShowCommentsInfo(Webpage webpage) { if (!webpage.AreCommentsEnabled(_getWebpageCommentingInfo.Get(webpage), _settings)) { return(new CommentsViewInfo { Disabled = true }); } var showCommentsInfo = new CommentsViewInfo { View = "Show", Model = _session.QueryOver <Comment>() .Where( comment => comment.Webpage == webpage && comment.Approved == true && comment.InReplyTo == null) //.Take(_settings.InitialNumberOfCommentsToShow) .List(), }; showCommentsInfo.ViewData["allow-reply"] = _settings.AllowGuestComments || CurrentRequestData.CurrentUser != null; showCommentsInfo.ViewData["webpage"] = webpage; return(showCommentsInfo); }
private ActionResult ReturnView(CommentsViewInfo info) { if (info.Disabled) { return(new EmptyResult()); } ViewData = info.ViewData; return(PartialView(info.View, info.Model)); }
public CommentsViewInfo GetShowCommentsInfo(Webpage webpage) { if (!webpage.AreCommentsEnabled(GetCommentingInfo(webpage), _settings)) { return(new CommentsViewInfo { Disabled = true }); } var allComments = _session.QueryOver <Comment>().Where(comment => comment.Webpage == webpage && comment.Approved == true) .OrderBy(x => x.CreatedOn).Asc.Cacheable().List(); var commentIds = allComments.Select(x => x.Id).ToList(); VoteCounts counts = null; var showCommentsInfo = new CommentsViewInfo { View = "Show", Model = new CommentTreeData { AllComments = allComments, UpvoteCounts = commentIds.Any() ? _session.QueryOver <Vote>().Where(x => x.IsUpvote && x.Comment.Id.IsIn(commentIds)) .SelectList(builder => { builder.SelectGroup(x => x.Comment.Id).WithAlias(() => counts.Comment); builder.SelectCount(x => x.Id).WithAlias(() => counts.Count); return(builder); }).TransformUsing(Transformers.AliasToBean <VoteCounts>()).List <VoteCounts>() : new List <VoteCounts>(), DownvoteCounts = commentIds.Any() ? _session.QueryOver <Vote>().Where(x => !x.IsUpvote && x.Comment.Id.IsIn(commentIds)) .SelectList(builder => { builder.SelectGroup(x => x.Comment.Id).WithAlias(() => counts.Comment); builder.SelectCount(x => x.Id).WithAlias(() => counts.Count); return(builder); }).TransformUsing(Transformers.AliasToBean <VoteCounts>()).List <VoteCounts>() : new List <VoteCounts>(), CurrentUser = CurrentRequestData.CurrentUser, Webpage = webpage }, ViewData = { ["allow-reply"] = _settings.AllowGuestComments || CurrentRequestData.CurrentUser != null, ["webpage"] = webpage } }; return(showCommentsInfo); }
public ActionResult ReplyTo(Comment comment) { CommentsViewInfo info = _commentsUiService.GetReplyToInfo(comment); return(ReturnView(info)); }
public ActionResult Show(Webpage webpage) { CommentsViewInfo info = _commentsUiService.GetShowCommentsInfo(webpage); return(ReturnView(info)); }