/// <summary>
 /// Delete an item in the data
 /// </summary>
 /// <param name="item">The UserVo to delete from the list</param>
 public void DeleteItem( UserVo item )
 {
     UserVo user = item as UserVo;
     for ( int i=0; i<Users.Count; i++ )
     {
         if ( Users[i].Username == item.Username )
         {
             Users.RemoveAt(i);
         }
     }
 }
        /// <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 );
        }
 /// <summary>
 /// Update an item in the data.
 /// </summary>
 /// <param name="item">The UserVo from the list to update</param>
 public void UpdateItem( UserVo item )
 {
     UserVo user = item as UserVo;
     for(int i=0; i<Users.Count; i++)
     {
         if( Users[i].Username == item.Username )
         {
             Users[i] = item;
         }
     }
 }
 /// <summary>
 ///  Add an item to the data
 /// </summary>
 /// <param name="item">The UserVo to add to the list</param>
 public void AddItem( UserVo item )
 {
     Users.Add( item );
 }
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            user = new UserVo
            {
                Username = Username.Text,
                Fname =  First.Text,
                Lname = Last.Text,
                Email = Email.Text,
                Password = Password.Password,
                Department = Department.SelectedItem as DeptEnum
            };

            if ( !user.isValid )
                return;

            if ( mode == MODE_ADD )
            {
                if(Add != null)
                    Add( this );
            }
            else
            {
                if(Update != null)
                    Update( this );
            }
        }
 /// <summary>
 /// Delete roles item attached to an user.
 /// </summary>
 /// <param name="item">The UserVo from who to delete roles</param>
 public void DeleteItem( UserVo item )
 {
     for( int i=0; i<Roles.Count; i++)
     {
         if( Roles[i].Username == item.Username )
         {
             Roles.RemoveAt(i);
             break;
         }
     }
 }
 /// <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;
             }
         }
     }
 }
 /// <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;
 }
 private void OnNew( object sender )
 {
     UserVo user = new UserVo();
     SendNotification( ApplicationFacade.NEW_USER, user );
 }