Esempio n. 1
0
 public CommentsViewInfo GetAddCommentsInfo(Webpage webpage)
 {
     if (!webpage.AreCommentsEnabled(GetCommentingInfo(webpage), _settings))
     {
         return(new CommentsViewInfo {
             Disabled = true
         });
     }
     if (!_settings.AllowGuestComments && CurrentRequestData.CurrentUser == null)
     {
         return(new CommentsViewInfo
         {
             View = "Login",
             Model = new LoginModel(),
         });
     }
     if (CurrentRequestData.CurrentUser == null)
     {
         return(new CommentsViewInfo
         {
             View = "Guest",
             Model = new GuestAddCommentModel {
                 WebpageId = webpage.Id
             },
         });
     }
     return(new CommentsViewInfo
     {
         View = "LoggedIn",
         Model = new LoggedInUserAddCommentModel {
             WebpageId = webpage.Id
         },
     });
 }
Esempio n. 2
0
        public CommentsViewInfo GetReplyToInfo(Comment comment)
        {
            Webpage webpage = comment.Webpage;

            if (webpage == null || !webpage.AreCommentsEnabled(GetCommentingInfo(webpage), _settings))
            {
                return(new CommentsViewInfo {
                    Disabled = true
                });
            }
            if (!_settings.AllowGuestComments && CurrentRequestData.CurrentUser == null)
            {
                return(new CommentsViewInfo {
                    Disabled = true
                });
            }
            if (CurrentRequestData.CurrentUser == null)
            {
                return(new CommentsViewInfo
                {
                    View = "GuestReply",
                    Model = new GuestAddCommentModel {
                        WebpageId = webpage.Id, InReplyTo = comment.Id
                    },
                });
            }
            return(new CommentsViewInfo
            {
                View = "LoggedInReply",
                Model = new LoggedInUserAddCommentModel {
                    WebpageId = webpage.Id, InReplyTo = comment.Id
                },
            });
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public override object GetModel(CurrentPageCommentsWidget widget)
        {
            Webpage currentPage = CurrentRequestData.CurrentPage;

            if (currentPage == null)
            {
                return(null);
            }
            CommentingInfo commentingInfo = _getWebpageCommentingInfo.Get(currentPage);

            if (!currentPage.AreCommentsEnabled(commentingInfo, _commentingSettings))
            {
                return(null);
            }
            return(currentPage);
        }