public static BORole GetByGuid(string guid)
        {
            BORole a = new BORole();
            SqlConnection con = new SqlConnection(GetConnectionString());

            con.Open();

            try
            {
                SqlCommand cmd = new SqlCommand("P_Role_GetByGUID", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SetVarCharParameter(cmd.Parameters, "@GUID", 50, guid, false);
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleResult);

                try
                {
                    while (rdr.Read())
                    {
                        a = new BORole(rdr);
                    }
                }
                finally
                {
                    rdr.Close();
                }
            }
            finally
            {
                con.Close();
            }
            return a;
        }
        public void Delete(string guid, BOUser currentUser)
        {
            UserRole userRole = GetRoleByGuid(guid);
            if (BORoleRightX.DeleteAllRightsByRoleID(guid))
            {
                BORole role = new BORole(userRole.RoleId);
                var preDeleteValue = role.CascadingDelete;
                role.CascadingDelete = true;
                role.Delete();
                role.CascadingDelete = preDeleteValue;
            }

            BOUserAudit.CreateAudit(currentUser, "Role Deleted", userRole.RoleName);
        }
        public RoleResult Save(UserRole userRole, BORoleRightXCollection roleRights)
        {
            try
            {
                if (userRole == null)
                {
                    return RoleResult.Failed;
                }
                else
                {
                    if (userRole.RoleId == SQLPersistent.NULL_INT64)
                    {
                        // Create Role
                        if (UserRole.GetByName(userRole.RoleName) != null)
                            return RoleResult.NameAlreadyExists;

                        BORole role = new BORole();
                        role.Name = userRole.RoleName;
                        role.RoleType = new BORoleType(userRole.RoleTypeId);
                        role.Description = userRole.Description;
                        role.Save();

                        UserRole newUserRole = UserRole.GetByName(userRole.RoleName);
                        if (newUserRole == null)
                        {
                            return RoleResult.Failed;
                        }
                        userRole = newUserRole;
                    }
                    UserRole.UserRoleResult userRoleResult = userRole.Save(roleRights);
                    switch (userRoleResult)
                    {
                        case UserRole.UserRoleResult.Success:
                            return RoleResult.Success;
                        case UserRole.UserRoleResult.NameAlreadyExists:
                            return RoleResult.NameAlreadyExists;
                        case UserRole.UserRoleResult.FailedToUpdateRights:
                            return RoleResult.FailedToUpdateRights;
                        default:
                            return RoleResult.Failed;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Failed to update Role.", ex);
                return RoleResult.Failed;
            }
        }
        public IEnumerable<BORoleRightX> GetRoleRights(BORole role)
        {
            var roleRightRepository = _repositoryFactory.GetRepository<BORoleRightX, BORoleRightXCollection>();

            return roleRightRepository.GetBy<BORole>(role);
        }
 public BORoleComparer(BORole.Columns column, BORole.SortDirections direction)
 {
     _column = column;
     _direction = direction;
 }
        public static bool UpdateRole(long roleId, string roleName, string description)
        {
            if (description == null)
                description = "";

            try
            {
                BORole role = new BORole(roleId);
                role.Description = description;
                role.Name = roleName;

                role.Save();

                return true;
            }
            catch (Exception ex)
            {
                logger.ErrorException("Failed to Update Role", ex);
                return false;
            }
        }