Ejemplo n.º 1
0
        /// <summary>
        /// Fills the list with subcategories found in the database, and fills the subcategories with their subcategories, until MaxRecursion
        /// level is reached, or all are accounted for. 
        /// </summary>
        /// <param name="db">The repository. Since read-only, any will do, but don't create one needlessly</param>
        /// <param name="ModelList">The list to fill</param>
        /// <param name="id">The id of the category, or null if primary categories are to be found</param>
        /// <param name="MaxRecursionLevel">0 means no recursion, only fill the current list.</param>
        private void ViewCategory_RecursivelyFillSubcategories(ForumRespository db, Forum_User CategoryReader, List<SubCategoryModel> ModelList, int id, int MaxRecursionLevel)
        {
            if (MaxRecursionLevel < 0) return;
            foreach (var SubCategory in db.GetSortedCategories(id))
            {
                if (!SubCategory.InheritPermissions && !db.CheckCategoryPermissions(SubCategory, CategoryReader, P => P.AllowView))
                    continue;
                SubCategoryModel SubModel = new SubCategoryModel() {
                    id = SubCategory.CategoryID,
                    Name = SubCategory.Name,
                    AllowPosts = SubCategory.AllowPosts
                };

                ModelList.Add(SubModel);
                if (!SubCategory.AllowPosts)
                {
                    ViewCategory_RecursivelyFillSubcategories(db, CategoryReader, SubModel.SubCategories, SubModel.id, MaxRecursionLevel - 1);
                }
                else
                {
                    IQueryable<Forum_Thread> Threads = db.GetSortedThreads(SubCategory.CategoryID);
                    SubModel.ThreadCount = Threads.Count();
                    if (SubModel.ThreadCount > 0)
                    {
                        SubModel.PostCount = Threads.Sum(T => T.Posts);
                        SubModel.LastPostTime = Threads.First().LastPostTime;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult RecentPosts()
        {
            using (ForumRespository db = new ForumRespository())
            {
                var Model = new RecentPostsViewModel();

                Model.AddNavigation("Recent Posts");

                Forum_User CurrentUser = GetCurrentUser(db);

                List<int> VisibleCategoryIDList = new List<int>();

                var Categories = db.GetAllCategories();

                foreach (var Category in Categories)
                {
                    if (db.CheckCategoryPermissions(Category, CurrentUser, P => P.AllowView))
                        VisibleCategoryIDList.Add(Category.CategoryID);
                }

                var Threads = db.GetSortedThreads().Where(T => VisibleCategoryIDList.Contains(T.CategoryID));

                ThreadInfoModelFromThread(db, CurrentUser, Threads.Take(THREADS_PER_PAGE), Model.ThreadInfoList);

                return View(Model);
            }
        }
Ejemplo n.º 3
0
        public ActionResult ViewCategory(CategoryViewModel model)
        {
            using (ForumRespository db = new ForumRespository())
            {
                Forum_User CurrentUser = GetCurrentUser(db);
                Forum_Category Category =  db.GetCategoryByID(model.id);

                if (Category == null)
                    return NotFoundView("Category");

                if (model.id != (int)BuildInCategory.Root)
                {
                    model.AddNavigation(Category);
                    model.Name = Category.Name;
                }
                else
                {
                    model.IncludeIndex = false;
                    model.AddNavigation("Index");
                    model.Name = "Index";
                }

                if (!db.CheckCategoryPermissions(Category, CurrentUser, P => P.AllowView))
                    return AuthenticationHelper.AccessDeniedView(model);

                ViewCategory_RecursivelyFillSubcategories(db, CurrentUser, model.SubCategories, model.id, Category.AllowPosts ? 0 : 1);

                if (Category.AllowPosts)
                {
                    IQueryable<Forum_Thread> SortedThreads = db.GetSortedThreads(Category.CategoryID);
                    model.PageCount = (SortedThreads.Count() - 1) / THREADS_PER_PAGE + 1;

                    model.AllowPosts = true;
                    ThreadInfoModelFromThread(db, CurrentUser, SortedThreads.Skip(THREADS_PER_PAGE * (model.page - 1)).Take(THREADS_PER_PAGE), model.Threads);
                }

                return View(model);
            }
        }
Ejemplo n.º 4
0
        public ActionResult MyPosts(int Page)
        {
            using (ForumRespository db = new ForumRespository())
            {

                var Model = new MyPostsViewModel();
                Model.AddNavigation("My Posts");

                if (!Request.IsAuthenticated)
                    return AuthenticationHelper.AccessDeniedView(Model); // Regardless of permissions, requires an account by neccecity

                Forum_User CurrentUser = GetCurrentUser(db);

                var Threads = db.GetSortedThreads(CurrentUser);

                Model.PageCount = (Threads.Count() - 1) / THREADS_PER_PAGE + 1;
                Model.Page = Page;

                ThreadInfoModelFromThread(db, CurrentUser, Threads.Skip(THREADS_PER_PAGE * (Page - 1)).Take(THREADS_PER_PAGE), Model.ThreadInfoList);

                return View(Model);
            }
        }