/// <summary>
        /// Add a role to this user
        /// </summary>
        /// <param name="user">The user to whom to add roles</param>
        /// <param name="role">The role to add</param>
        public void AddRoleToUser( UserVo user, RoleEnum role )
        {
            bool result = false;
            if( !DoesUserHaveRole( user, role ) )
            {
                for( int i=0; i<Roles.Count; i++ )
                {
                    if( Roles[i].Username == user.Username )
                    {
                        ObservableCollection<RoleEnum> userRoles = Roles[i].Roles as ObservableCollection<RoleEnum>;
                        userRoles.Add( role );
                        result = true;
                        break;
                    }
                }
            }

            SendNotification( ApplicationFacade.ADD_ROLE_RESULT, result );
        }
Ejemplo n.º 2
0
 public bool Equals(RoleEnum role)
 {
     return((int)Ordinal == (int)role.Ordinal && Value == role.Value);
 }
 /// <summary>
 /// Determine if the user has a given role.
 /// </summary>
 /// <param name="user">The user to search for roles</param>
 /// <param name="role">The role to search for</param>
 /// <returns></returns>
 public bool DoesUserHaveRole( UserVo user, RoleEnum role )
 {
     bool hasRole = false;
     for( int i=0; i<Roles.Count; i++ )
     {
         if( Roles[i].Username == user.Username )
         {
             ObservableCollection<RoleEnum> userRoles = Roles[i].Roles as ObservableCollection<RoleEnum>;
             for( int j=0; j<userRoles.Count; j++ )
             {
                 if( userRoles[j].Equals(role) )
                 {
                     hasRole = true;
                     break;
                 }
             }
             break;
         }
     }
     return hasRole;
 }
 /// <summary>
 /// Remove a role from the user
 /// </summary>
 /// <param name="user">The user to whom to remove roles</param>
 /// <param name="role">The role to remove</param>
 public void RemoveRoleFromUser( UserVo user, RoleEnum role )
 {
     if( DoesUserHaveRole( user, role ) )
     {
         for( int i=0; i<Roles.Count; i++ )
         {
             if( Roles[i].Username == user.Username )
             {
                 ObservableCollection<RoleEnum> userRoles = Roles[i].Roles as ObservableCollection<RoleEnum>;
                 for( int j=0; j<userRoles.Count; j++ )
                 {
                     if( userRoles[j].Equals(role) )
                     {
                         userRoles.RemoveAt(j);
                         break;
                     }
                 }
                 break;
             }
         }
     }
 }
 public bool Equals( RoleEnum role )
 {
     return ( (int)Ordinal == (int)role.Ordinal && Value == role.Value );
 }