コード例 #1
0
        static async Task RunAsync()
        {
            client.BaseAddress = new Uri("http://localhost:5000/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json")
                );
            try{
                programCheck prog2 = new programCheck();

                //Get the product
                prog2 = await GetProductAsync("http://localhost:5000/api/programcheck/1");

                //Show the product
                ShowProgramCheck(prog2);
                //Only show programCount off the prog2
                Console.WriteLine(prog2.programCount);

                // Update the product
                Console.WriteLine("Updating programCount...");
                prog2.programCount = 7;
                await UpdateProductAsync(prog2);

                ShowProgramCheck(prog2);
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
            Console.ReadLine();
        }
コード例 #2
0
        static async Task <programCheck> GetProductAsync(string path)
        {
            programCheck        prog1    = null;
            HttpResponseMessage response = await client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                prog1 = await response.Content.ReadAsAsync <programCheck>();
            }
            return(prog1);
        }
コード例 #3
0
        static async Task <programCheck> UpdateProductAsync(programCheck product)
        {
            HttpResponseMessage response = await client.PutAsJsonAsync(
                $"api/programcheck/{product.Id}", product);

            response.EnsureSuccessStatusCode();

            // Deserialize the updated product from the response body.
            product = await response.Content.ReadAsAsync <programCheck>();

            return(product);
        }
コード例 #4
0
 static void ShowProgramCheck(programCheck prog1)
 {
     Console.WriteLine($"Name: {prog1.programName}, {prog1.programCount}, {prog1.programLimit}");
 }