Exemplo n.º 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;
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
 }
Exemplo n.º 5
0
 public bool UserInRole(Forum_User User, Forum_Role Role)
 {
     return UserInRole(User, Role.RoleID);
 }
Exemplo n.º 6
0
 public bool UserInRole(Forum_User User, BuildInRole Role)
 {
     return UserInRole(User, (int)Role);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 10
0
 partial void UpdateForum_User(Forum_User instance);
Exemplo n.º 11
0
 public void DeleteUser(Forum_User ToDelete)
 {
     db.Forum_Users.DeleteOnSubmit(ToDelete);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
                    }
                }
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 15
0
 partial void DeleteForum_User(Forum_User instance);
Exemplo n.º 16
0
 public void AddUser(Forum_User NewUser)
 {
     db.Forum_Users.InsertOnSubmit(NewUser);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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];
        }
Exemplo n.º 19
0
 partial void InsertForum_User(Forum_User instance);