Exemple #1
0
        static async Task <Uri> CreateNotesDataAsync(NotesData notesData)
        {
            HttpResponseMessage response = await client.PostAsJsonAsync("api/notesData", notesData);

            response.EnsureSuccessStatusCode();

            // return URI of the created resource.
            return(response.Headers.Location);
        }
Exemple #2
0
        static async Task <NotesData> UpdateNotesDataAsync(NotesData notesData)
        {
            HttpResponseMessage response = await client.PutAsJsonAsync($"api/notesData/{notesData.UserID}", notesData);

            response.EnsureSuccessStatusCode();

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

            return(notesData);
        }
Exemple #3
0
        static async Task <NotesData> GetSingNotesDataAsync(string path)
        {
            NotesData           notesData = null;
            HttpResponseMessage response  = await client.GetAsync($"api/notesData/{notesData.GuidID}");

            // HttpResponseMessage response = await client.GetAsync(path);
            if (response.IsSuccessStatusCode)
            {
                notesData = await response.Content.ReadAsAsync <NotesData>();
            }
            return(notesData);
        }
Exemple #4
0
        static async Task RunAsync()
        {
            client.BaseAddress = new Uri("https://notesapiservice.azurewebsites.net/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            try
            {
                // Create a new notesData
                NotesData notesData = new NotesData {
                    UserID = "*****@*****.**", Notes = ""
                };

                var url = await CreateNotesDataAsync(notesData);

                Console.WriteLine($"Created at {url}");

                // Get the notesData
                notesData = await GetNotesDataAsync(url.PathAndQuery);

                ShowNotesData(notesData);

                // Update the notesData
                Console.WriteLine("Updating notes...");
                notesData.Notes = "Updated note from windows client";
                await UpdateNotesDataAsync(notesData);

                // Get the updated notesData
                notesData = await GetNotesDataAsync(url.PathAndQuery);

                ShowNotesData(notesData);

                // Delete the notesData
                var statusCode = await DeleteNotesDataAsync(notesData.UserID, notesData.GuidID.ToString());

                Console.WriteLine($"Deleted (HTTP Status = {(int)statusCode})");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
Exemple #5
0
 static void ShowNotesData(NotesData notesData)
 {
     Console.WriteLine($"ID: {notesData.UserID}\tNoteid: {notesData.GuidID}\tNotes: {notesData.Notes}");
 }