public ActionResult MarkAllAsRead(int?forumCategoryID) { ZkDataContext db = new ZkDataContext(); var threads = db.ForumThreads.Where(x => x.ForumCategoryID == forumCategoryID || forumCategoryID == null); foreach (ForumThread thread in threads) { ForumThreadLastRead lastRead = Global.Account.ForumThreadLastReads.FirstOrDefault(x => x.ForumThreadID == thread.ForumThreadID); if (lastRead.LastRead < thread.LastPost) { thread.UpdateLastRead(Global.AccountID, false, DateTime.UtcNow); } } db.SubmitChanges(); return(RedirectToAction("Index", new { categoryID = forumCategoryID })); }
/// <summary> /// <para>Returns an appropriately formatted link with thread title and mail icon for a thread</para> /// <para>(e.g. bold = posted in; italics = new; grey icon = already read)</para> /// </summary> /// <param name="thread">The thread to print</param> /// <returns></returns> public static MvcHtmlString Print(this HtmlHelper helper, ForumThread thread) { var url = Global.UrlHelper(); ForumThreadLastRead lastRead = null; ForumLastRead lastReadForum = null; DateTime? lastTime = null; if (Global.Account != null) { lastRead = Global.Account.ForumThreadLastReads.FirstOrDefault(x => x.ForumThreadID == thread.ForumThreadID); lastReadForum = Global.Account.ForumLastReads.FirstOrDefault(x => x.ForumCategoryID == thread.ForumCategoryID); if (lastReadForum != null) { lastTime = lastReadForum.LastRead; } } if (lastRead != null && (lastTime == null || lastRead.LastRead > lastTime)) { lastTime = lastRead.LastRead; } ForumPost post = null; if (lastTime != null) { post = thread.ForumPosts.FirstOrDefault(x => x.Created > lastTime); } int page = post != null?ZeroKWeb.Controllers.ForumController.GetPostPage(post) : (thread.PostCount - 1) / GlobalConst.ForumPostsPerPage; string link; if (page > 0) { link = url.Action("Thread", "Forum", new { id = thread.ForumThreadID, page = page }); } else { link = url.Action("Thread", "Forum", new { id = thread.ForumThreadID }); } link = string.Format("<a href='{0}' title='$thread${1}' style='word-break:break-all;'>", link, thread.ForumThreadID); string format; if (lastTime == null) { format = "<span>{0}<img src='/img/mail/mail-unread.png' height='15' /><i>{1}</i></a></span>"; } else { if (lastTime >= thread.LastPost) { format = "<span>{0}<img src='/img/mail/mail-read.png' height='15' />{1}</a></span>"; } else { if (lastRead != null && lastRead.LastPosted != null) { format = "<span>{0}<img src='/img/mail/mail-new.png' height='15' /><b>{1}</b></a></span>"; } else { format = "<span>{0}<img src='/img/mail/mail-unread.png' height='15' />{1}</a></span>"; } } } string title = HttpUtility.HtmlEncode(thread.Title); if (!string.IsNullOrEmpty(thread.WikiKey)) { title = string.Format("<span style='color:lightblue'>[{0}]</span> {1}", thread.WikiKey, title); } return(new MvcHtmlString(string.Format(format, link, title))); }
public static MvcHtmlString Print(this HtmlHelper helper, ForumThread thread) { var url = Global.UrlHelper(); ForumThreadLastRead lastRead = null; DateTime? lastTime = null; if (Global.Account != null) { lastRead = Global.Account.ForumThreadLastReads.FirstOrDefault(x => x.ForumThreadID == thread.ForumThreadID); } if (lastRead != null) { lastTime = lastRead.LastRead; } ForumPost post = null; if (lastTime != null) { post = thread.ForumPosts.FirstOrDefault(x => x.Created > lastTime); } int page = post != null?ZeroKWeb.Controllers.ForumController.GetPostPage(post.ForumPostID) : (thread.PostCount - 1) / GlobalConst.ForumPostsPerPage; string link; if (page > 0) { link = url.Action("Thread", "Forum", new { id = thread.ForumThreadID, page = page }); } else { link = url.Action("Thread", "Forum", new { id = thread.ForumThreadID }); } link = string.Format("<a href='{0}' title='$thread${1}'>", link, thread.ForumThreadID); string format; if (lastRead == null) { format = "<span>{0}<img src='/img/mail/mail-unread.png' height='15' /><i>{1}</i></a></span>"; } else { if (lastRead.LastRead >= thread.LastPost) { format = "<span>{0}<img src='/img/mail/mail-read.png' height='15' />{1}</a></span>"; } else { if (lastRead.LastPosted != null) { format = "<span>{0}<img src='/img/mail/mail-new.png' height='15' /><b>{1}</b></a></span>"; } else { format = "<span>{0}<img src='/img/mail/mail-unread.png' height='15' />{1}</a></span>"; } } } return(new MvcHtmlString(string.Format(format, link, HttpUtility.HtmlEncode(thread.Title)))); }