/// <summary>
 /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName.
 /// </summary>
 /// <param name="user">The user to check for</param>
 /// <param name="roleName">The role to check for</param>
 /// <returns><b>true</b> if user is in role, <b>false</b> otherwise</returns>
 public bool IsUserInRole(User user, string roleName)
 {
     if (user == null)
     {
         return(false);
     }
     return(RoleDataSource.IsUserInRole(user.UserId, roleName));
 }
        /// <summary>
        /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName.
        /// </summary>
        /// <param name="username">The name of the user to check for</param>
        /// <param name="roleName">The role to check for</param>
        /// <returns><b>true</b> if user is in role, <b>false</b> otherwise</returns>
        public override bool IsUserInRole(string username, string roleName)
        {
            User user = UserDataSource.LoadForUserName(username);

            if (user == null)
            {
                return(false);
            }
            return(RoleDataSource.IsUserInRole(user.UserId, roleName));
        }
        /// <summary>
        /// Removes a role from the data source for the configured application Name
        /// </summary>
        /// <param name="roleName">The role to delete</param>
        /// <param name="throwOnPopulatedRole">If true, throw an exception if roleName has one or more members and do not delete roleName.</param>
        /// <returns><b>true</b> if role is deleted <b>false</b> otherwise</returns>
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            Role role = RoleDataSource.LoadForRolename(roleName);

            if (role == null)
            {
                return(false);
            }
            return(role.Delete());
        }
示例#4
0
        private void InternalReload()
        {
            roleIdLookup = new Dictionary <string, int>();
            RoleCollection allRoles = RoleDataSource.LoadAll();

            foreach (Role role in allRoles)
            {
                roleIdLookup[role.LoweredName] = role.RoleId;
            }
        }
        /// <summary>
        /// Gets a list of all the roles for the configured applicationName.
        /// </summary>
        /// <returns>A string array containing the names of all the roles stored in the data source for the configured applicationName.</returns>
        public override string[] GetAllRoles()
        {
            RoleCollection roleCollection = RoleDataSource.LoadAll();

            string[] allRoles = new string[roleCollection.Count];
            for (int index = 0; index < roleCollection.Count; index++)
            {
                allRoles[index] = roleCollection[index].Name;
            }
            return(allRoles);
        }
 /// <summary>
 /// Makes sure that the default roles expected for a store are available
 /// in the database
 /// </summary>
 internal static void EnsureDefaultRoles()
 {
     string[] defaultRoles = Role.AllAdminRoles;
     //make sure the admin role exists
     foreach (string roleName in defaultRoles)
     {
         Role role = RoleDataSource.LoadForRolename(roleName);
         if (role == null)
         {
             role      = new Role();
             role.Name = roleName;
             role.Save();
         }
     }
 }
        /// <summary>
        /// Gets a list of the roles that a specified user is in for the configured applicationName.
        /// </summary>
        /// <param name="username">The user to return a list of roles for.</param>
        /// <returns>A string array containing the names of all the roles that the specified user is in for the configured applicationName.</returns>
        public override string[] GetRolesForUser(string username)
        {
            string[] userRoles = new string[0];
            User     user      = UserDataSource.LoadForUserName(username);

            if (user != null)
            {
                RoleCollection roles = RoleDataSource.LoadForUser(user.UserId);
                if (roles.Count > 0)
                {
                    userRoles = new string[roles.Count];
                    for (int i = 0; i < roles.Count; i++)
                    {
                        userRoles[i] = roles[i].Name;
                    }
                }
            }
            return(userRoles);
        }
示例#8
0
 /// <summary>
 /// Determines whether this group has the given role assigned.
 /// </summary>
 /// <param name="name">The name of the role to check.</param>
 /// <returns>True if the group has the given role; false otherwise.</returns>
 public bool IsInRole(string name)
 {
     return(RoleDataSource.IsGroupInRole(this.GroupId, name));
 }
示例#9
0
 /// <summary>
 /// Determines whether a user is in the given role.
 /// </summary>
 /// <param name="roleId">The unique ID of the role to check.</param>
 /// <returns>True if the user is in the given role; false otherwise.</returns>
 public bool IsInRole(int roleId)
 {
     return(RoleDataSource.IsUserInRole(this.UserId, roleId));
 }
示例#10
0
 /// <summary>
 /// Determines whether a user is in the given role.
 /// </summary>
 /// <param name="name">The name of the role to check.</param>
 /// <returns>True if the user is in the given role; false otherwise.</returns>
 public bool IsInRole(string name)
 {
     return(RoleDataSource.IsUserInRole(this.UserId, name));
 }
 public static Role Load(Int32 roleId)
 {
     return(RoleDataSource.Load(roleId, true));
 }
 public static RoleCollection LoadForGroup(Int32 groupId, int maximumRows, int startRowIndex)
 {
     return(RoleDataSource.LoadForGroup(groupId, maximumRows, startRowIndex, string.Empty));
 }
 public static RoleCollection LoadForGroup(Int32 groupId, string sortExpression)
 {
     return(RoleDataSource.LoadForGroup(groupId, 0, 0, sortExpression));
 }
 public static RoleCollection LoadForGroup(Int32 groupId)
 {
     return(RoleDataSource.LoadForGroup(groupId, 0, 0, string.Empty));
 }
示例#15
0
        /// <summary>
        /// Loads a role instance given the name.
        /// </summary>
        /// <param name="name">The case-insensitive role name.</param>
        /// <returns>The role instance, or null if the role is not found.</returns>
        public static Role LoadForRolename(string name)
        {
            int roleId = RoleDataSource.GetIdByName(name);

            return(RoleDataSource.Load(roleId));
        }
示例#16
0
 public static RoleCollection LoadAll(int maximumRows, int startRowIndex)
 {
     return(RoleDataSource.LoadAll(maximumRows, startRowIndex, string.Empty));
 }
示例#17
0
 public static RoleCollection LoadAll(string sortExpression)
 {
     return(RoleDataSource.LoadAll(0, 0, sortExpression));
 }
示例#18
0
 public static RoleCollection LoadAll()
 {
     return(RoleDataSource.LoadAll(0, 0, string.Empty));
 }
 /// <summary>
 /// Gets a value indicating whether the specified role name already exists in the role data source for the configured applicationName.
 /// </summary>
 /// <param name="roleName">The role name to check</param>
 /// <returns><b>true</b> if role already exists, <b>false</b> otherwise</returns>
 public override bool RoleExists(string roleName)
 {
     return(RoleDataSource.GetIdByName(roleName) > 0);
 }