public void Post(TopicSaveModel model) { var t = new Topic(); t.Body = model.Body; t.MemberId = Members.GetCurrentMemberId(); t.Created = DateTime.Now; t.ParentId = model.Forum; TopicService.Save(t); }
public void SendNotification(Topic topic, string memberName, string url) { var db = ApplicationContext.Current.DatabaseContext.Database; var sql = new Sql().Select("memberId") .From("forumSubscribers") .Where("forumId = @forumId", new { forumId = topic.ParentId }); var results = db.Query<int>(sql).ToList(); using (ContextHelper.EnsureHttpContext()) { var memberShipHelper = new MembershipHelper(UmbracoContext.Current); { foreach (var memberId in results.Where(memberId => memberId != topic.MemberId)) { try { var member = memberShipHelper.GetById(memberId); if (member.GetPropertyValue<bool>("bugMeNot")) continue; var from = new MailAddress(_details.SelectSingleNode("//from/email").InnerText, _details.SelectSingleNode("//from/name").InnerText); var contentService = ApplicationContext.Current.Services.ContentService; var forum = contentService.GetById(topic.ParentId); var subject = _details.SelectSingleNode("//subject").InnerText; subject = string.Format(subject, forum.Name); var domain = _details.SelectSingleNode("//domain").InnerText; var body = _details.SelectSingleNode("//body").InnerText; body = string.Format(body, forum.Name, "https://" + domain + url, memberName, topic.Title, HttpUtility.HtmlDecode(umbraco.library.StripHtml(topic.Body))); var mailMessage = new MailMessage { Subject = subject, Body = body }; mailMessage.To.Add(member.GetPropertyValue<string>("Email")); mailMessage.From = from; using (var smtpClient = new SmtpClient()) { smtpClient.Send(mailMessage); } } catch (Exception exception) { LogHelper.Error<NewForumTopic>( string.Format("Error sending mail to member id {0}", memberId), exception); } } } } }
public void ChangeCategory(Topic topic, int newCategory) { var eventArgs = new TopicEventArgs() { Topic = topic }; if (Moving.RaiseAndContinue(this, eventArgs)) { topic.ParentId = newCategory; _databaseContext.Database.Save(topic); Moved.Raise(this, eventArgs); } else CancelledByEvent.Raise(this, eventArgs); }
public ExpandoObject Topic(TopicSaveModel model) { dynamic o = new ExpandoObject(); var t = new Topic(); t.Body = model.Body; t.Title = model.Title; t.MemberId = Members.GetCurrentMemberId(); t.Created = DateTime.Now; t.ParentId = model.Forum; t.UrlName = url.FormatUrl(model.Title); t.Updated = DateTime.Now; t.Version = model.Version; t.Locked = false; t.LatestComment = 0; t.LatestReplyAuthor = 0; t.Replies = 0; t.Score = 0; t.Answer = 0; t.LatestComment = 0; t.IsSpam = Members.GetCurrentMember().GetPropertyValue<bool>("blocked") || t.DetectSpam(); TopicService.Save(t); if (t.IsSpam) SpamChecker.SendSlackSpamReport(t.Body, t.Id, "topic", t.MemberId); o.url = string.Format("{0}/{1}-{2}", library.NiceUrl(t.ParentId), t.Id, t.UrlName); return o; }
public void Delete(Topic topic) { var eventArgs = new TopicEventArgs() { Topic = topic }; if (Deleting.RaiseAndContinue(this, eventArgs)) { _databaseContext.Database.Delete(topic); Deleted.Raise(this, eventArgs); } else CancelledByEvent.Raise(this, eventArgs); }
public void Lock(Topic topic) { var eventArgs = new TopicEventArgs() { Topic = topic }; if (Locking.RaiseAndContinue(this, eventArgs)) { topic.Locked = true; _databaseContext.Database.Save(topic); Locked.Raise(this, eventArgs); } else CancelledByEvent.Raise(this, eventArgs); }
/* CRUD */ public Topic Save(Topic topic) { var newTopic = topic.Id <= 0; var eventArgs = new TopicEventArgs() { Topic = topic }; if (newTopic) Creating.Raise(this, eventArgs); else Updating.Raise(this, eventArgs); if (!eventArgs.Cancel) { //save entity _databaseContext.Database.Save(topic); if (newTopic) Created.Raise(this, eventArgs); else Updated.Raise(this, eventArgs); } else { CancelledByEvent.Raise(this, eventArgs); } return topic; }