private static bool CheckForDuplicate(string comment) { DateTime since = DateTime.Now.AddMinutes(-15); HomeAppsLib.db.NFL_forum dupe = HomeAppsLib.LibCommon.DBModel().NFL_forums.FirstOrDefault(x => x.comment == comment && x.insert_dt > since); return(dupe != null); }
internal static void AddNewNFLForumComment(int week, string username, int?refId, string comment, string title, bool emailOnReply) { if (CheckForDuplicate(comment)) { return; } var data = HomeAppsLib.LibCommon.DBModel(); HomeAppsLib.db.NFL_forum post = new HomeAppsLib.db.NFL_forum(); post.week = week; post.ref_id = refId; post.comment = comment; post.title = title; post.insert_dt = DateTime.Now; post.username = username; post.alerted = false; post.emailOnReply = emailOnReply; data.NFL_forums.InsertOnSubmit(post); data.SubmitChanges(); if (refId.HasValue) { var parentPost = HomeAppsLib.LibCommon.DBModel().NFL_forums.FirstOrDefault(x => x.id == refId.Value); if (parentPost != null && parentPost.emailOnReply && parentPost.username != username) { SendPostReplyEmail(post, parentPost.username); } } }
private static void SendPostReplyEmail(HomeAppsLib.db.NFL_forum post, string usernameToSendEmail) { string subject = CurrentUser.name + " just replied to your post!"; string to = DBModel().users.First(x => x.name == usernameToSendEmail).email; string body = HomeAppsLib.EmailSubscriptions.GenerateDiscPostEmailBodyText(post); HomeAppsLib.LibCommon.SendSystemEmailWithSignature(to, subject, body); }
internal static DateTime MaxReplyDate(HomeAppsLib.db.NFL_forum post) { DateTime result = DateTime.MinValue; foreach (var reply in HomeAppsLib.LibCommon.DBModel().NFL_forums.Where(x => x.ref_id == post.id)) { if (reply.insert_dt.HasValue && reply.insert_dt.Value > result) { result = reply.insert_dt.Value; } DateTime maxSubReply = MaxReplyDate(reply); if (maxSubReply > result) { result = maxSubReply; } } return(result); }