/// <summary> /// The bind data. /// </summary> public void BindData() { // default since date is now this.sinceDate = DateTime.UtcNow; // default since option is "since last visit" this.sinceValue = 0; // is any "since"option selected if (this.Since.SelectedItem != null) { // get selected value this.sinceValue = int.Parse(this.Since.SelectedItem.Value); // decrypt selected option if (this.sinceValue == 9999) { // all // get all, from the beginning this.sinceDate = DateTimeHelper.SqlDbMinTime(); } else if (this.sinceValue > 0) { // days // get posts newer then defined number of days this.sinceDate = DateTime.UtcNow - TimeSpan.FromDays(this.sinceValue); } else if (this.sinceValue < 0) { // hours // get posts newer then defined number of hours this.sinceDate = DateTime.UtcNow + TimeSpan.FromHours(this.sinceValue); } } // we want to filter topics since last visit if (this.sinceValue == 0) { this.sinceDate = this.Get <IYafSession>().LastVisit ?? DateTime.UtcNow; if (this.CurrentMode.Equals(TopicListMode.Unread)) { this.sinceDate = this.Get <IReadTrackCurrentUser>().LastRead; } } // filter by category object categoryIdObject = null; // is category set? if (this.PageContext.Settings.CategoryID != 0) { categoryIdObject = this.PageContext.Settings.CategoryID; } // we'll hold topics in this table DataTable topicList = null; // set the page size here int basePageSize = this.Get <YafBoardSettings>().MyTopicsListPageSize; this.PagerTop.PageSize = basePageSize; // page index in db which is returned back is +1 based! int nCurrentPageIndex = this.PagerTop.CurrentPageIndex; // now depending on mode fill the table switch (this.CurrentMode) { case TopicListMode.Active: topicList = LegacyDb.topic_active( this.PageContext.PageBoardID, categoryIdObject, this.PageContext.PageUserID, this.sinceDate, DateTime.UtcNow, nCurrentPageIndex, basePageSize, this.Get <YafBoardSettings>().UseStyledNicks, this.Get <YafBoardSettings>().UseReadTrackingByDatabase); break; case TopicListMode.Unanswered: topicList = LegacyDb.topic_unanswered( this.PageContext.PageBoardID, categoryIdObject, this.PageContext.PageUserID, this.sinceDate, DateTime.UtcNow, nCurrentPageIndex, basePageSize, this.Get <YafBoardSettings>().UseStyledNicks, this.Get <YafBoardSettings>().UseReadTrackingByDatabase); break; case TopicListMode.Unread: topicList = LegacyDb.topic_unread( this.PageContext.PageBoardID, categoryIdObject, this.PageContext.PageUserID, this.sinceDate, DateTime.UtcNow, nCurrentPageIndex, basePageSize, this.Get <YafBoardSettings>().UseStyledNicks, this.Get <YafBoardSettings>().UseReadTrackingByDatabase); break; case TopicListMode.User: topicList = LegacyDb.Topics_ByUser( this.PageContext.PageBoardID, categoryIdObject, this.PageContext.PageUserID, this.sinceDate, DateTime.UtcNow, nCurrentPageIndex, basePageSize, this.Get <YafBoardSettings>().UseStyledNicks, this.Get <YafBoardSettings>().UseReadTrackingByDatabase); break; case TopicListMode.Favorite: topicList = this.GetRepository <FavoriteTopic>().Details( (YafContext.Current.Settings.CategoryID == 0) ? null : (int?)YafContext.Current.Settings.CategoryID, this.PageContext.PageUserID, this.sinceDate, DateTime.UtcNow, nCurrentPageIndex, basePageSize, this.Get <YafBoardSettings>().UseStyledNicks, this.Get <YafBoardSettings>().UseReadTrackingByDatabase); break; } if (topicList == null) { this.PagerTop.Count = 0; return; } if (topicList.Rows.Count <= 0) { this.PagerTop.Count = 0; this.TopicList.DataSource = null; this.TopicList.DataBind(); return; } this.topics = topicList; DataTable topicsNew = topicList.Copy(); foreach (var thisTableRow in topicsNew .Rows.Cast <DataRow>() .Where(thisTableRow => thisTableRow["LastPosted"] != DBNull.Value && thisTableRow["LastPosted"].ToType <DateTime>() <= this.sinceDate)) { thisTableRow.Delete(); } // styled nicks topicsNew.AcceptChanges(); if (this.Get <YafBoardSettings>().UseStyledNicks) { this.Get <IStyleTransform>().DecodeStyleByTable(topicsNew, false, new[] { "LastUserStyle", "StarterStyle" }); } // let's page the results this.PagerTop.Count = topicsNew.HasRows() ? topicsNew.AsEnumerable().First().Field <int>("TotalRows") : 0; this.TopicList.DataSource = topicsNew; // Get new Feeds links this.BindFeeds(); // data bind controls this.DataBind(); }