Esempio n. 1
0
        public async Task <ActionResult> Threads(int pageNo = 1)
        {
            var userID = this.HttpContext.Session.GetUserID();

            if (userID <= 0)
            {
                // not found
                return(RedirectToAction("Index", "Home"));
            }

            int rowCount = this.HttpContext.Session.GetInt32(SessionKeys.MyThreadsRowCount) ?? 0;

            if (rowCount <= 0)
            {
                rowCount = await UserGuiHelper.GetRowCountLastThreadsForUserAsync(this.HttpContext.Session.GetForumsWithActionRight(ActionRights.AccessForum), userID,
                                                                                  this.HttpContext.Session.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers),
                                                                                  userID);

                this.HttpContext.Session.SetInt32(SessionKeys.MyThreadsRowCount, rowCount);
            }

            var systemSettings = await _cache.GetSystemDataAsync();

            int pageSize = systemSettings.PageSizeSearchResults;

            if (pageSize <= 0)
            {
                pageSize = 50;
            }

            int rowCountCapped = rowCount;

            if (rowCount > 500)
            {
                // maximum is 500
                rowCountCapped = 500;
            }

            int numberOfPages = (rowCountCapped / pageSize);

            if ((numberOfPages * pageSize) < rowCountCapped)
            {
                numberOfPages++;
            }

            var data = new MyThreadsData()
            {
                RowCount = rowCount, NumberOfPages = numberOfPages, PageNo = pageNo
            };

            data.ThreadRows = await UserGuiHelper.GetLastThreadsForUserAggregatedDataAsync(this.HttpContext.Session.GetForumsWithActionRight(ActionRights.AccessForum), userID,
                                                                                           this.HttpContext.Session.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers),
                                                                                           userID, pageSize, pageNo);

            return(View(data));
        }