public SubForum(string subForumTitle, Forum parentForun, ForumGeneratorContext db)
 {
     this.subForumTitle = subForumTitle;
     this.moderators = new List<Moderator>();
     this.parentForum = parentForun;
     Moderator m = new Moderator(parentForum.admin, ForumGenerator_Version2_Server.Users.Moderator.modLevel.ALL);
     this.moderators.Add(m);
     db.Moderators.Add(m);
     db.SaveChanges();
     this.discussions = new List<Discussion>();
     this.vocabulary = new HashSet<Word>();
 }
        public static bool checkModeratorAuthorization(SubForum sf, string userName, string password, Moderator.modLevel modLevel)
        {
            // forum admin is also a subforum moderator
            try
            {
                Moderator moderator = sf.getModerator(userName);
                if (moderator != null && moderator.user.password == password &&
                    moderator.user.isLogged() && moderator.level == modLevel)
                    return true;

                return false;
            }
            catch
            {
                return false;
            }
        }
 public Moderator(Moderator m)
 {
     this.moderatorId = m.moderatorId;
     this.user = new User(m.user);
     this.level = m.level;
 }
        public Boolean addModerator(string modUserName, ForumGeneratorContext db, ForumGenerator_Version2_Server.Users.Moderator.modLevel level)
        {
            // check if user is registered to the forum
            Moderator newModerator = new Moderator(parentForum.getUser(modUserName), level);
            if (moderatorExists(modUserName))
                throw new UnauthorizedOperationException(ForumGeneratorDefs.EXIST_MODERATOR);
            if (!newModerator.user.isConfirmed)
                throw new UnauthorizedOperationException(ForumGeneratorDefs.INACTIVE_USR);

            else
            {
                // OK, moderator is not exist
                this.moderators.Add(newModerator);
                db.Moderators.Add(newModerator);
                db.SaveChanges();
                return true;
            }
        }
 internal bool changeModLevel(int forumId, int subForumId, string moderatorName, Moderator.modLevel newLevel, ForumGeneratorContext db)
 {
     Moderator moderator = this.getModerator(moderatorName);
     moderator.level = newLevel;
     db.Entry(db.Moderators.Find(moderator.moderatorId)).CurrentValues.SetValues(moderator);
     db.SaveChanges();
     return true;
 }
 public bool changeModLevel(int forumId, int subForumId, string moderatorName, Moderator.modLevel newLevel)
 {
     this.logger.logAction("performing changeModLevel: forumId: " + forumId +
                                                    "\tsubForumId: " + subForumId +
                                                    "\tmoderatorName: " + moderatorName +
                                                    "\tnewLevel: " + newLevel.ToString());
     try
     {
         return this.getForum(forumId).getSubForum(subForumId).changeModLevel(forumId, subForumId, moderatorName, newLevel, this.db);
     }
     catch (Exception e)
     {
         this.logger.logError("changeModLevel: " + e.Message);
         throw e;
     }
 }