Exemplo n.º 1
0
        static async Task <string> GetUserIdForUsername(string username)
        {
            //@skydocs.start(users.getall)
            //Create an API request for retrieving all users
            var getUsersRequest = new Skylight.Api.Authentication.V1.UsersRequests.GetUsersRequest();

            //Execute the API request
            var result = await SkyManager.ApiClient.ExecuteRequestAsync(getUsersRequest);

            //The users will be stored as a list in the result's Content, so we can iterate through them
            foreach (var user in result.Content)
            {
                if (user.Username == username)
                {
                    return(user.Id);
                }
            }
            return(null);
            //@skydocs.end()
        }
Exemplo n.º 2
0
        //As the name suggests, this method will get the user ID for a given username -- or will return null, if the user doesn't exist
        static async Task <string> GetUserIdForUsername(string username)
        {
            //Create an API request for retrieving all users
            var getUsersRequest = new Skylight.Api.Authentication.V1.UsersRequests.GetUsersRequest();

            //Execute the API request
            var result = await SkyManager.ApiClient.ExecuteRequestAsync(getUsersRequest);

            //Handle the resulting status code appropriately
            switch (result.StatusCode)
            {
            case System.Net.HttpStatusCode.Forbidden:
                Console.Error.WriteLine("Error getting users: Permission forbidden.");
                throw new Exception("Error getting users.");

            case System.Net.HttpStatusCode.Unauthorized:
                Console.Error.WriteLine("Error getting users: Method call was unauthenticated.");
                throw new Exception("Error getting users.");

            case System.Net.HttpStatusCode.OK:
                Console.WriteLine("Successfully retrieved users.");
                break;

            default:
                Console.Error.WriteLine("Unhandled users list retrieval status code: " + result.StatusCode);
                throw new Exception("Error getting users.");
            }

            //The users will be stored as a list in the result's Content, so we can iterate through them
            foreach (var user in result.Content)
            {
                if (user.Username == username)
                {
                    return(user.Id);
                }
            }

            return(null);
        }