public static void Adauga_Bere() { Bere b = new Bere(); string url = URL; url.Substring(10); url += "\beers"; Console.WriteLine("Introduce ID: "); b.Id = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Introduce numele: "); b.Nume = Console.ReadLine(); StringContent content = new StringContent(JsonConvert.SerializeObject(b)); var client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json"); var clientResponse = client.PostAsync(url, content).Result; Console.WriteLine(clientResponse); }
public static List <Bere> GetBeersData(JObject obj) { List <Bere> lista_beri = new List <Bere>(); try { var beers = obj["_embedded"]["beer"]; int i = 0; while (beers[i] != null) { try { Bere b = new Bere(); if (beers[i]["Id"] != null) { b.Id = Convert.ToInt32(beers[i]["Id"]); } if (beers[i]["Name"] != null) { b.Nume = beers[i]["Name"].ToString(); } if (beers[i]["BreweryId"] != null) { b.Id_Berarie = Convert.ToInt32(beers[i]["BreweryId"]); } if (beers[i]["BreweryName"] != null) { b.NumeBerarie = beers[i]["BreweryName"].ToString(); } if (beers[i]["StyleId"] != null) { b.StyleID = Convert.ToInt32(beers[i]["StyleId"]); } if (beers[i]["StyleName"] != null) { b.StyleName = beers[i]["StyleName"].ToString(); } if (beers[i]["_links"]["style"]["href"] != null) { b.StyleLink = beers[i]["_links"]["style"]["href"].ToString(); } if (beers[i]["_links"]["self"]["href"] != null) { b.SelfLink = beers[i]["_links"]["self"]["href"].ToString(); } try { if (beers[i]["_links"]["review"]["href"] != null) { b.ReviewLink = beers[i]["_links"]["review"]["href"].ToString(); } } catch { } lista_beri.Add(b); } catch { } i++; } } catch { } return(lista_beri); }