Пример #1
0
        //
        // RoleProvider.IsUserInRole
        //

        public override bool IsUserInRole(string username, string rolename)
        {
            bool userIsInRole = false;

            try
            {
                Professional_Gift_Card_System.Models.IUserInRolesDAO UserInRoleDAO = new Professional_Gift_Card_System.Models.UserInRolesDAO();
                if (UserInRoleDAO.IsUserInRole(username, rolename, pApplicationName))
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "IsUserInRole");
                }
                else
                {
                    throw e;
                }
            }
            return(userIsInRole);
        }
Пример #2
0
        //
        // System.Web.Security.RoleProvider methods.
        //

        //
        // RoleProvider.AddUsersToRoles
        //

        public override void AddUsersToRoles(string[] usernames, string[] rolenames)
        {
            foreach (string rolename in rolenames)
            {
                if (!RoleExists(rolename))
                {
                    throw new ProviderException("Role name not found.");
                }
            }

            foreach (string username in usernames)
            {
                if (username.Contains(","))
                {
                    throw new ArgumentException("User names cannot contain commas.");
                }

                foreach (string rolename in rolenames)
                {
                    if (IsUserInRole(username, rolename))
                    {
                        throw new ProviderException("User is already in role.");
                    }
                }
            }


            try
            {
                Professional_Gift_Card_System.Models.IUserInRolesDAO UserInRoleDAO = new Professional_Gift_Card_System.Models.UserInRolesDAO();
                foreach (string username in usernames)
                {
                    foreach (string rolename in rolenames)
                    {
                        UserInRoleDAO.AddUserToRole(username, rolename, ApplicationName);
                    }
                }
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "AddUsersToRoles");
                }
                else
                {
                    throw e;
                }
            }
        }