Ejemplo n.º 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 = 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 = Roles.GetRolesForUser();
            o.cssClass = model.Parent > 0 ? "level-2" : string.Empty;
            o.parent = model.Parent;

            return o;
        }
Ejemplo n.º 2
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;
            CommentService.Save(c);
        }