Ejemplo n.º 1
0
        public void CreateRole(string roleName, string description)
        {
            if (String.IsNullOrEmpty(roleName))
            {
                throw new ProviderException("Role name cannot be empty or null.");
            }
            if (roleName.Contains(","))
            {
                throw new ArgumentException("Role names cannot contain commas.");
            }
            if (RoleExists(roleName))
            {
                throw new ProviderException("Role name already exists.");
            }
            if (roleName.Length > 256)
            {
                throw new ProviderException("Role name cannot exceed 256 characters.");
            }

            try
            {
                using (XtraUnitOfWork uow = new XtraUnitOfWork(DataLayer))
                {
                    XpoRole role = new XpoRole(uow)
                    {
                        RoleName = roleName, ApplicationName = this.ApplicationName, Description = description
                    };
                    uow.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "CreateRole");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 2
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole = true)
        {
            if (!RoleExists(roleName))
            {
                throw new ProviderException("Role does not exist.");
            }

            if (throwOnPopulatedRole && GetUsersInRole(roleName).Length > 0)
            {
                throw new ProviderException("Cannot delete a populated role.");
            }

            try
            {
                using (XtraUnitOfWork uow = new XtraUnitOfWork(DataLayer))
                {
                    XpoRole role = uow.FindObject <XpoRole>(new GroupOperator(
                                                                GroupOperatorType.And,
                                                                new BinaryOperator(XpoRole.Fields.ApplicationName, ApplicationName, BinaryOperatorType.Equal),
                                                                new BinaryOperator(XpoRole.Fields.RoleName, roleName, BinaryOperatorType.Equal)));
                    uow.Delete(role);
                    uow.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "DeleteRole");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw ex;
                }
            }

            return(!RoleExists(roleName));
        }