public CommentService(DatabaseContext dbContext, TopicService topicService) { if (dbContext == null) throw new ArgumentNullException("dbContext"); if (topicService == null) throw new ArgumentNullException("topicService"); _databaseContext = dbContext; _topicService = topicService; }
void TopicSolved(object sender, ActionEventArgs e) { var ts = new TopicService(ApplicationContext.Current.DatabaseContext); var cs = new CommentService(ApplicationContext.Current.DatabaseContext, ts); uPowers.BusinessLogic.Action a = (uPowers.BusinessLogic.Action)sender; if (a.Alias == "TopicSolved") { var c = cs.GetById(e.ItemId); if (c != null) { var t = ts.GetById(c.TopicId); //if performer and author of the topic is the same... go ahead.. if ((e.PerformerId == t.MemberId || ModeratorRoles.Split(',').Any(x => Roles.IsUserInRole(x))) && t.Answer == 0) { //receiver of points is the comment author. e.ReceiverId = c.MemberId; //remove any previous votes by the author on this comment to ensure the solution is saved instead of just the vote a.ClearVotes(e.PerformerId, e.ItemId); //this uses a non-standard coloumn in the forum schema, so this is added manually.. t.Answer = c.Id; ts.Save(t); } } } }
public SimpleDataSet CreateNewDocument(int id) { var ts = new TopicService(ApplicationContext.Current.DatabaseContext); var forumTopic = ts.QueryById(id); var simpleDataSet = new SimpleDataSet { NodeDefinition = new IndexedNode(), RowData = new Dictionary<string, string>() }; return MapTopicToSimpleDataIndexItem(forumTopic, simpleDataSet, forumTopic.Id, "forum"); }
public IEnumerable<SimpleDataSet> GetAllData(string indexType) { var ts = new TopicService(ApplicationContext.Current.DatabaseContext); foreach (var topic in ts.QueryAll(maxCount:int.MaxValue)) { //Add the item to the index.. var simpleDataSet = new SimpleDataSet { NodeDefinition = new IndexedNode(), RowData = new Dictionary<string, string>() }; yield return MapTopicToSimpleDataIndexItem(topic, simpleDataSet, topic.Id, "forum"); } }
void TopicVote(object sender, ActionEventArgs e) { var ts = new TopicService(ApplicationContext.Current.DatabaseContext); uPowers.BusinessLogic.Action a = (uPowers.BusinessLogic.Action)sender; if (a.Alias == "LikeTopic" || a.Alias == "DisLikeTopic") { var t = ts.GetById(e.ItemId); e.ReceiverId = t.MemberId; } }
public static void SendSlackSpamReport(string postBody, int topicId, string commentType, int memberId) { var ts = new TopicService(ApplicationContext.Current.DatabaseContext); using (var client = new WebClient()) { var topic = ts.GetById(topicId); var post = string.Format("Topic title: *{0}*\n\n Link to topic: http://our.umbraco.org{1}\n\n", topic.Title, topic.GetUrl()); post = post + string.Format("{0} text: {1}\n\n", commentType, postBody); post = post + string.Format("Go to member http://our.umbraco.org/member/{0}\n\n", memberId); var body = string.Format("The following forum post was marked as spam by the spam system, if this is incorrect make sure to mark it as ham.\n\n{0}", post); if (memberId != 0) { var member = ApplicationContext.Current.Services.MemberService.GetById(memberId); if (member != null) { var querystring = string.Format("api?ip={0}&email={1}&f=json", Utils.GetIpAddress(), HttpUtility.UrlEncode(member.Email)); body = body + string.Format("Check the StopForumSpam rating: http://api.stopforumspam.org/{0}", querystring); } } body = body.Replace("&", "&").Replace("<", "<").Replace(">", ">"); var values = new NameValueCollection { {"channel", ConfigurationManager.AppSettings["SlackChannel"]}, {"token", ConfigurationManager.AppSettings["SlackToken"]}, {"username", ConfigurationManager.AppSettings["SlackUsername"]}, { "icon_url", ConfigurationManager.AppSettings["SlackIconUrl"]}, {"text", body} }; try { var data = client.UploadValues("https://slack.com/api/chat.postMessage", "POST", values); var response = client.Encoding.GetString(data); } catch (Exception ex) { Log.Add(LogTypes.Error, new User(0), -1, string.Format("Posting update to Slack failed {0} {1}", ex.Message, ex.StackTrace)); } } }
void CommentService_Created(object sender, uForum.CommentEventArgs e) { var ts = new TopicService(ApplicationContext.Current.DatabaseContext); //Subscribe to topic var ns = new NotificationService(ApplicationContext.Current.DatabaseContext); ns.SubscribeToForumTopic(e.Comment.TopicId, e.Comment.MemberId); //data for notification: var membershipHelper = new MembershipHelper(Umbraco.Web.UmbracoContext.Current); var member = membershipHelper.GetById(e.Comment.MemberId); var memberName = string.Empty; if (member != null) memberName = member.Name; var topic = ts.GetById(e.Comment.TopicId); //send notifications InstantNotification not = new InstantNotification(); not.Invoke(Config.ConfigurationFile, Config.AssemblyDir, "NewComment", e.Comment, topic, topic.GetUrl(), memberName); }
void CommentVote(object sender, ActionEventArgs e) { uPowers.BusinessLogic.Action a = (uPowers.BusinessLogic.Action)sender; var ts = new TopicService(ApplicationContext.Current.DatabaseContext); var cs = new CommentService(ApplicationContext.Current.DatabaseContext, ts); if (a.Alias == "LikeComment" || a.Alias == "DisLikeComment") { var c = cs.GetById(e.ItemId); if (c != null) { e.ReceiverId = c.MemberId; } } else if (a.Alias == "TopicSolved") { var c = cs.GetById(e.ItemId); var t = ts.GetById(c.TopicId); e.Cancel = t.Answer > 0; } }
public void Flag(Flag flag) { var post = string.Format("A {0} has been flagged as spam for a moderator to check\n", flag.TypeOfPost); var member = Members.GetById(flag.MemberId); post = post + string.Format("Flagged by member {0} https://our.umbraco.org/member/{1}\n", member.Name, member.Id); var topicId = flag.Id; var ts = new TopicService(ApplicationContext.Current.DatabaseContext); if (flag.TypeOfPost == "comment") { var cs = new CommentService(ApplicationContext.Current.DatabaseContext, ts); var comment = cs.GetById(flag.Id); topicId = comment.TopicId; } var topic = ts.GetById(topicId); post = post+ string.Format("Topic title: *{0}*\n\n Link to {1}: http://our.umbraco.org{2}{3}\n\n", topic.Title, flag.TypeOfPost, topic.GetUrl(), flag.TypeOfPost == "comment" ? "#comment-" + flag.Id : string.Empty); SendSlackNotification(post); }
protected ForumControllerBase() { TopicService = new TopicService(DatabaseContext); CommentService = new CommentService(DatabaseContext, TopicService); ForumService = new ForumService(DatabaseContext); }