Little refactor and bugfix

This commit is contained in:
Sebastiaan Janssen
2016-10-30 12:47:41 +01:00
parent ddac31b8bc
commit 7e82ea86ec
2 changed files with 8 additions and 6 deletions
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Net.Mail;
using System.Web;
using System.Web.Hosting;
using System.Xml;
using OurUmbraco.Forum.Services;
@@ -25,11 +24,14 @@ namespace OurUmbraco.NotificationsCore.Notifications
{
var notifications = new XmlDocument();
notifications.Load(Config.ConfigurationFile);
var settings = notifications.SelectSingleNode("//global");
var node = notifications.SelectSingleNode(string.Format("//instant//notification [@name = '{0}']", notificationName));
var details = new XmlDocument();
var cont = details.CreateElement("details");
cont.AppendChild(details.ImportNode(settings, true));
cont.AppendChild(details.ImportNode(node, true));
_details = details.AppendChild(cont);
@@ -52,16 +54,16 @@ namespace OurUmbraco.NotificationsCore.Notifications
{
var memberShipHelper = new MembershipHelper(UmbracoContext.Current);
var member = memberShipHelper.GetById(memberId);
using (var smtpClient = new SmtpClient())
{
var fromEmail = _details.SelectSingleNode("//from/email").InnerText;
var fromName = _details.SelectSingleNode("//from/name").InnerText;
var fromMailAddress = new MailAddress(fromEmail, fromName);
var subject = string.Format("{0} - '{1}'", _details.SelectSingleNode("//subject").InnerText, topic.Title);
var body = _details.SelectSingleNode("//body").InnerText;
var domain = _details.SelectSingleNode("//domain").InnerText;
var body = _details.SelectSingleNode("//body").InnerText;
body = string.Format(body, topic.Title, "https://" + domain + topic.GetUrl());
if (member.GetPropertyValue<bool>("bugMeNot") == false)
@@ -17,9 +17,9 @@ namespace OurUmbraco.NotificationsCore.Notifications
var db = ApplicationContext.Current.DatabaseContext.Database;
var sql = new Sql("SELECT id, memberId FROM forumTopics WHERE answer = 0 AND (markAsSolutionReminderSent IS NULL OR markAsSolutionReminderSent = 0) AND replies > 0 AND updated < getdate() - 7 AND created > '2016-10-01 00:00:00' AND id NOT IN (SELECT topicId FROM notificationMarkAsSolution) ORDER BY created DESC");
var results = db.Query<ReminderTopic>(sql);
var reminder = new MarkAsSolutionReminder();
foreach (var reminderTopic in results)
{
var reminder = new MarkAsSolutionReminder();
var jobId = BackgroundJob.Schedule(() => reminder.SendNotification(reminderTopic.Id, reminderTopic.MemberId), TimeSpan.FromMinutes(10));
}
}