Exemplo n.º 1
0
 //POST: add word book
 public static async Task AddWordBook(WordBook book)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://localhost:37533/");
         await client.PostAsJsonAsync("api/wordbooks", book);
     }
 }
Exemplo n.º 2
0
 //PUT: update word book
 public static async Task UpdateWordBook(int id, WordBook book)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://localhost:37533/");
         await client.PutAsJsonAsync("api/wordbooks/" + id, book);
     }
 }
Exemplo n.º 3
0
        //GET: get word book by id
        public static async Task <WordBook> GetWordBook(int id)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:37533/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await client.GetAsync("api/wordbooks/" + id);

                if (response.IsSuccessStatusCode)
                {
                    WordBook book = await response.Content.ReadAsAsync <WordBook>();

                    return(book);
                }
                return(null);
            }
        }