コード例 #1
0
        public ExpandoObject Comment(CommentSaveModel model)
        {
            dynamic o = new ExpandoObject();
            var     currentMemberId = Members.GetCurrentMemberId();

            var c = new Comment();

            c.Body            = model.Body;
            c.MemberId        = currentMemberId;
            c.Created         = DateTime.Now;
            c.ParentCommentId = model.Parent;
            c.TopicId         = model.Topic;
            c.IsSpam          = Members.GetCurrentMember().GetPropertyValue <bool>("blocked") || c.DetectSpam();
            CommentService.Save(c);
            if (c.IsSpam)
            {
                SpamChecker.SendSlackSpamReport(c.Body, c.TopicId, "comment", c.MemberId);
            }

            o.id       = c.Id;
            o.body     = c.Body.Sanitize().ToString();
            o.topicId  = c.TopicId;
            o.authorId = c.MemberId;
            o.created  = c.Created.ConvertToRelativeTime();
            var author = Members.GetById(currentMemberId);

            o.authorKarma = author.Karma();
            o.authorName  = author.Name;
            o.roles       = author.GetRoles();
            o.cssClass    = model.Parent > 0 ? "level-2" : string.Empty;
            o.parent      = model.Parent;
            o.isSpam      = c.IsSpam;

            return(o);
        }
コード例 #2
0
        public ActionResult Save(CommentSaveModel m)
        {
            if (ModelState.IsValid && m.SessionId == Session.SessionID) {
                using (var db = new DataContext()) {
                    // Check if the comment belongs to a standard entity.
                    var isPage = db.Pages.Where(p => p.Id == m.ParentId).SingleOrDefault() != null ;
                    var isPost = !isPage && db.Posts.Where(p => p.Id == m.ParentId).SingleOrDefault() != null ;
                    var isMedia = !isPage && !isPost && db.Posts.Where(c => c.Id == m.ParentId).SingleOrDefault() != null ;
                    var isUload = !isPage && !isPost && !isMedia && db.Uploads.Where(u => u.Id == m.ParentId).SingleOrDefault() != null ;

                    // Now get the comment settings
                    var sett = Areas.Manager.Models.CommentSettingsModel.Get() ;

                    // Check comment settings according to type
                    if (isPage && (!sett.EnablePages || (!User.Identity.IsAuthenticated && !sett.EnableAnonymous)))
                        return Redirect("~/") ;
                    else if (isPost && (!sett.EnablePosts || (!User.Identity.IsAuthenticated && !sett.EnableAnonymous)))
                        return Redirect("~/") ;
                    else if (isMedia && (!sett.EnableMedia || (!User.Identity.IsAuthenticated && !sett.EnableAnonymous)))
                        return Redirect("~/") ;
                    else if (isUload && (!sett.EnableUploads || (!User.Identity.IsAuthenticated && !sett.EnableAnonymous)))
                        return Redirect("~/") ;

                    Comment comment = null ;

                    // Try to load the comment if this is an update
                    if (m.Id != null)
                        comment = db.Comments.Where(c => c.Id == m.Id).SingleOrDefault() ;

                    // If no existing comment was found, create a new
                    if (comment == null) {
                        comment = new Comment() ;
                        comment.Attach(db, EntityState.Added) ;
                    }

                    // If the user isn't authenticated, add user info
                    if (!User.Identity.IsAuthenticated) {
                        comment.AuthorName = m.AuthorName ;
                        comment.AuthorEmail = m.AuthorEmail ;
                    }

                    // Update standard properties
                    comment.Title = m.Title ;
                    comment.Body = m.Body ;

                    db.SaveChanges() ;
                }
            }
            return new RedirectResult("~/") ;
        }
コード例 #3
0
        public void Comment(int id, CommentSaveModel model)
        {
            var c = CommentService.GetById(id);

            if (c == null)
            {
                throw new Exception("Comment not found");
            }

            if (c.MemberId != Members.GetCurrentMemberId() && Members.IsAdmin() == false)
            {
                throw new Exception("You cannot edit this comment");
            }

            c.Body = model.Body;
            // This is an edit, don't update topic post count
            CommentService.Save(c, false);
        }
コード例 #4
0
        public ExpandoObject Comment(CommentSaveModel model)
        {
            dynamic expandoObject = new ExpandoObject();
            var     currentMember = Members.GetCurrentMember();

            var comment = new Comment
            {
                Body            = model.Body,
                MemberId        = currentMember.Id,
                Created         = DateTime.Now,
                ParentCommentId = model.Parent,
                TopicId         = model.Topic
            };

            comment.IsSpam = currentMember.GetPropertyValue <bool>("blocked") || comment.DetectSpam();
            CommentService.Save(comment);
            if (comment.IsSpam)
            {
                SpamChecker.SendSlackSpamReport(comment.Body, comment.TopicId, "comment", comment.MemberId);
            }

            expandoObject.id          = comment.Id;
            expandoObject.body        = comment.Body.Sanitize().ToString();
            expandoObject.topicId     = comment.TopicId;
            expandoObject.authorId    = comment.MemberId;
            expandoObject.created     = comment.Created.ConvertToRelativeTime();
            expandoObject.authorKarma = currentMember.Karma();
            expandoObject.authorName  = currentMember.Name;
            expandoObject.roles       = currentMember.GetRoles().GetBadges();
            expandoObject.cssClass    = model.Parent > 0 ? "level-2" : string.Empty;
            expandoObject.parent      = model.Parent;
            expandoObject.isSpam      = comment.IsSpam;

            SignalRcommentSaved(expandoObject);

            return(expandoObject);
        }
コード例 #5
0
        public ActionResult Save(CommentSaveModel m)
        {
            if (ModelState.IsValid && m.SessionId == Session.SessionID)
            {
                using (var db = new DataContext()) {
                    // Check if the comment belongs to a standard entity.
                    var isPage  = db.Pages.Where(p => p.Id == m.ParentId).SingleOrDefault() != null;
                    var isPost  = !isPage && db.Posts.Where(p => p.Id == m.ParentId).SingleOrDefault() != null;
                    var isMedia = !isPage && !isPost && db.Posts.Where(c => c.Id == m.ParentId).SingleOrDefault() != null;
                    var isUload = !isPage && !isPost && !isMedia && db.Uploads.Where(u => u.Id == m.ParentId).SingleOrDefault() != null;

                    // Now get the comment settings
                    var sett = Areas.Manager.Models.CommentSettingsModel.Get();

                    // Check comment settings according to type
                    if (isPage && (!sett.EnablePages || (!App.Instance.UserProvider.IsAuthenticated && !sett.EnableAnonymous)))
                    {
                        return(Redirect("~/"));
                    }
                    else if (isPost && (!sett.EnablePosts || (!App.Instance.UserProvider.IsAuthenticated && !sett.EnableAnonymous)))
                    {
                        return(Redirect("~/"));
                    }
                    else if (isMedia && (!sett.EnableMedia || (!App.Instance.UserProvider.IsAuthenticated && !sett.EnableAnonymous)))
                    {
                        return(Redirect("~/"));
                    }
                    else if (isUload && (!sett.EnableUploads || (!App.Instance.UserProvider.IsAuthenticated && !sett.EnableAnonymous)))
                    {
                        return(Redirect("~/"));
                    }

                    Comment comment = null;

                    // Try to load the comment if this is an update
                    if (m.Id != null)
                    {
                        comment = db.Comments.Where(c => c.Id == m.Id).SingleOrDefault();
                    }

                    // If no existing comment was found, create a new
                    if (comment == null)
                    {
                        comment = new Comment();
                        comment.Attach(db, EntityState.Added);
                    }

                    // If the user isn't authenticated, add user info
                    if (!App.Instance.UserProvider.IsAuthenticated)
                    {
                        comment.AuthorName  = m.AuthorName;
                        comment.AuthorEmail = m.AuthorEmail;
                    }

                    // Update standard properties
                    comment.Title = m.Title;
                    comment.Body  = m.Body;

                    db.SaveChanges();
                }
            }
            return(new RedirectResult("~/"));
        }