private void CheckModerators(ForumFolder folder)
        {
            LayoutName = null;
            if (folder != null)
            {
                User user = (Session.Contains("User")) ? (User) Session["User"] : null;
                if (user != null)
                {
                    bool userbelongstogroup = false;
                    if (((bool)Session["isAdmin"]) || ((bool)Session["isRoot"]))
                        userbelongstogroup = true;

                    foreach (Group g in user.Groups)
                    {
                        if ((folder.Forum.Admins != null) && (g.Id == folder.Forum.Admins.Id))
                            userbelongstogroup = true;
                    }

                    foreach (Group g in user.Groups)
                    {
                        if ((folder.Moderators != null) && (g.Id == folder.Moderators.Id))
                            userbelongstogroup = true;
                    }

                    if (userbelongstogroup == false)
                        throw new Unauthorized();
                }
                else
                    throw new Unauthorized();
            }
            else
                throw new Unauthorized();
        }
        private void DeleteFolderAndMessages(ForumFolder folder)
        {
            Forum forum = GetForumBelongsFolder(folder);
            if (folder.FoldersChildren.Count > 0)
            {
                foreach (ForumFolder f in folder.FoldersChildren)
                    f.Delete();
                folder.FoldersChildren.Clear();
                folder.Save();
            }
            else
            {
                foreach (ForumMessage message in folder.ForumMessages)
                    DeleteMessagesChildren(message);
                folder.ForumMessages.Clear();
                folder.Save();
            }

            if (folder.Parent == null)
            {
                forum.ForumFolders.Remove(folder);
                folder.Delete();
                forum.Save();
            }
            else
            {
                ForumFolder parent = folder.Parent;
                parent.FoldersChildren.Remove(folder);
                folder.Delete();
                parent.Save();
            }
        }
 private Forum GetForumBelongsFolder(ForumFolder folder)
 {
     if (folder.Forum != null)
         return folder.Forum;
     else
         return folder.Parent.Forum;
 }
        public void CreateFolder(int idForum, int idFolderParent)
        {
            if (idForum != 0)
                CheckAdmins(Forum.Find(idForum));
            else
                CheckAdmins(GetForumBelongsFolder(ForumFolder.Find(idFolderParent)));

            PropertyBag["groups"] = Group.FindAll();
            PropertyBag["idForum"] = idForum;
            PropertyBag["idFolderParent"] = idFolderParent;
            PropertyBag["forum"] = new ForumFolder();

            LayoutName = null;
        }