Example #1
0
 public bool AddUserRoleLink(Forum_Role Role, Forum_User User)
 {
     if (UserInRole(User, Role)) return false;
     var Link = new Forum_UserRoleLink();
     Link.RoleID = Role.RoleID;
     Link.UserID = User.UserID;
     db.Forum_UserRoleLinks.InsertOnSubmit(Link);
     return true;
 }
Example #2
0
        public static bool CheckCategoryPermissions(this ForumRespository db, Forum_Category Category, Forum_User User, Func<Forum_Permission, bool> PermissionCheck)
        {
            if (Identity.IsAdmin) return true; // Since Administrators can change rules, they might as well ignore them.

            var Permissions = db.GetPermissions(Category, User);
            foreach (var P in Permissions)
            {
                if (PermissionCheck(P)) return true;
            }
            return false;
        }
Example #3
0
        public static bool CheckRolePermissions(this ForumRespository db, Forum_User User, Func<Forum_Role, bool> PermissionCheck)
        {
            if (Identity.IsAdmin) return true; // Since Administrators can change rules, they might as well ignore them.

            var Roles = db.GetUserRoles(User);
            foreach (var R in Roles)
            {
                if (PermissionCheck(R)) return true;
            }
            return false;
        }
Example #4
0
 public bool UserInRole(Forum_User User, int RoleID)
 {
     if (RoleID == (int)BuildInRole.Everyone) return true;
     if (User == null) return false;
     if (RoleID == (int)BuildInRole.RegisteredUser) return true;
     return db.Forum_UserRoleLinks.SingleOrDefault(L => L.RoleID == RoleID && L.UserID == User.UserID) != null;
 }
Example #5
0
 public bool UserInRole(Forum_User User, Forum_Role Role)
 {
     return UserInRole(User, Role.RoleID);
 }
Example #6
0
 public bool UserInRole(Forum_User User, BuildInRole Role)
 {
     return UserInRole(User, (int)Role);
 }
Example #7
0
 public void SetLastPost(Forum_Thread Thread, Forum_User User, int PostNumber, bool IncreaseOnly = true)
 {
     var Last = db.Forum_ViewedPosts.SingleOrDefault(P => P.Forum_User == User && P.Forum_Thread == Thread);
     if (Last == null)
     {
         Last = new Forum_ViewedPost();
         Last.Forum_Thread = Thread;
         Last.Forum_User = User;
         db.Forum_ViewedPosts.InsertOnSubmit(Last);
     }
     else if (Last.LastPost >= PostNumber && IncreaseOnly) return;
     Last.LastPost = PostNumber;
 }
Example #8
0
 public void RemoveUserFromRole(Forum_User User, Forum_Role Role)
 {
     Forum_UserRoleLink Link = db.Forum_UserRoleLinks.SingleOrDefault(L => L.Forum_Role == Role && L.Forum_User == User);
     if (Link == null) return;
     db.Forum_UserRoleLinks.DeleteOnSubmit(Link);
 }
Example #9
0
        public IEnumerable<Forum_Role> GetUserRoles(Forum_User User)
        {
            var Roles = new List<Forum_Role>();
            Roles.Add(GetBuildInRole(BuildInRole.Everyone)); // Everyone includes everyone

            if (User == null || User.UserID == (int)BuildInUser.Guest) return Roles; // Guests are only part of Everyone.

            Roles.Add(GetBuildInRole(BuildInRole.RegisteredUser)); // Not a guest: Registered user at least

            var UserRoles = from L in db.Forum_UserRoleLinks where L.UserID == User.UserID join R in db.Forum_Roles on L.RoleID equals R.RoleID select R;
            return Roles.Concat(UserRoles);
        }
Example #10
0
 partial void UpdateForum_User(Forum_User instance);
Example #11
0
 public void DeleteUser(Forum_User ToDelete)
 {
     db.Forum_Users.DeleteOnSubmit(ToDelete);
 }
Example #12
0
 public int GetLastPost(Forum_Thread Thread, Forum_User User)
 {
     var Last = db.Forum_ViewedPosts.SingleOrDefault(P => P.Forum_User == User && P.Forum_Thread == Thread);
     return Last == null ? 0 : Last.LastPost;
 }
Example #13
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;
                    }
                }
            }
        }
Example #14
0
        void ThreadInfoModelFromThread(ForumRespository db, Forum_User User, IEnumerable<Forum_Thread> Threads, ICollection<ThreadInfoViewModel> InfoCollection)
        {
            foreach (var Thread in Threads)
            {
                ThreadInfoViewModel NewThreadInfo = new ThreadInfoViewModel()
                {
                    ThreadTitle = Thread.Title,
                    ThreadID = Thread.ThreadID,
                    PostCount = Thread.Posts
                };

                InfoCollection.Add(NewThreadInfo);

                if (User == null)
                    NewThreadInfo.LastViewedPost = Thread.Posts;
                else
                    NewThreadInfo.LastViewedPost = db.GetLastPost(Thread, User);

                NewThreadInfo.Locked = Thread.Locked;

                NewThreadInfo.PageCount = (Thread.Posts - 1) / POSTS_PER_PAGE + 1;
                NewThreadInfo.LastViewedPostPage = NewThreadInfo.LastViewedPost / POSTS_PER_PAGE + 1;
                NewThreadInfo.LastViewedPostID = NewThreadInfo.LastViewedPost % POSTS_PER_PAGE + 1;

                Forum_Post LastPost = Thread.Forum_Posts.Last();
                NewThreadInfo.LastPoster = new UserViewModel();
                NewThreadInfo.LastPoster.Name = LastPost.Forum_User.Username;
                NewThreadInfo.LastPoster.UserID = LastPost.Forum_User.UserID;
                NewThreadInfo.LastPostTime = LastPost.TimeStamp;
            }
        }
Example #15
0
 partial void DeleteForum_User(Forum_User instance);
Example #16
0
 public void AddUser(Forum_User NewUser)
 {
     db.Forum_Users.InsertOnSubmit(NewUser);
 }
Example #17
0
 public IQueryable<Forum_Thread> GetSortedThreads(Forum_User Participant)
 {
     return (from P in db.Forum_Posts where P.Forum_User == Participant select P.Forum_Thread).Distinct().OrderByDescending(T => T.LastPostTime);
 }
Example #18
0
        public IEnumerable<Forum_Permission> GetPermissions(Forum_Category Category, Forum_User User)
        {
            if (!PermissionCache.ContainsKey(Category.CategoryID))
            {
                var CategoryIDList = new List<int>();
               FillCategoryIDListRecursively(CategoryIDList, Category);

                var Roles = GetUserRoles(User).Select(R => R.RoleID);
                PermissionCache.Add(Category.CategoryID, from L in db.Forum_PermissionsLinks
                                  where CategoryIDList.Contains(L.CategoryID) && Roles.Contains(L.RoleID)
                                  join P in db.Forum_Permissions on L.PermissionID equals P.PermissionID
                                  select P);
            }
            return PermissionCache[Category.CategoryID];
        }
Example #19
0
 partial void InsertForum_User(Forum_User instance);