Example #1
0
        /// <summary>
        /// 更新指定ID的用户的用户权限
        /// </summary>
        /// <param name="userNames">用户名</param>
        /// <param name="permissions">权限类型</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdatePermision(String userName, String permissions)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            PermissionType permission = AdminManager.GetPermission(permissions);
            Boolean        success    = UserRepository.Instance.UpdateEntityPermision(userName, permission) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No user's permission was updated!"));
            }

            return(MethodResult.SuccessAndLog("Admin update permission, name = {0}, permission = {1}", userName, ((Int32)permission).ToString()));
        }