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; }
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); }