示例#1
0
 //POST: add word card
 public static async Task AddWordCard(WordCard card)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://localhost:37533/");
         await client.PostAsJsonAsync("api/wordcards", card);
     }
 }
示例#2
0
 //PUT: update word card
 public static async Task UpdateWordCard(int id, WordCard card)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://localhost:37533/");
         await client.PutAsJsonAsync("api/wordcards/" + id, card);
     }
 }
示例#3
0
        //GET: get word card by id
        public static async Task <WordCard> GetWordCard(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/wordcards/" + id);

                if (response.IsSuccessStatusCode)
                {
                    WordCard card = await response.Content.ReadAsAsync <WordCard>();

                    return(card);
                }
                else
                {
                    return(null);
                }
            }
        }