void AddBeer(BeerData data) { Console.Write("Introduceti id:"); string id = Console.ReadLine(); Console.Write("Introduceti nume:"); string nume = Console.ReadLine(); string href = "/beers/" + id; Beer beer = new Beer(); beer.Href = href; data.Link.Beer = new List <Beer>(data.Link.Beer) { beer }.ToArray(); Beer2 beer2 = new Beer2(); beer2.Name = nume; beer2.Id = id; beer2.Link = new _links4(); beer2.Link.Self = new Self(); beer2.Link.Self.Href = href; data.Embedded.Beer = new List <Beer2>(data.Embedded.Beer) { beer2 }.ToArray(); String json = JsonConvert.SerializeObject(data); }
void ListBeers(BeerData data) { foreach (var beer in data.Embedded.Beer) { Console.Write(beer.Id + ". " + beer.Name + "\n"); } }
static void Main(string[] args) { Program program = new Program(); string option; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Accept", "application/hal+json"); var response = client.GetAsync("http://datc-rest.azurewebsites.net/breweries").Result; var data = response.Content.ReadAsStringAsync().Result; Data breweriesObj = JsonConvert.DeserializeObject <Data>(data); var beerResponse = client.GetAsync("http://datc-rest.azurewebsites.net/beers").Result; var beerData = beerResponse.Content.ReadAsStringAsync().Result; BeerData beerObj = JsonConvert.DeserializeObject <BeerData>(beerData); // Console.Write(JsonConvert.SerializeObject(beerObj)); do { program.Meniu(); option = Console.ReadLine(); switch (option) { case "0": break; case "1": program.ListBreweries(breweriesObj); break; case "2": program.ListBeers(beerObj); break; case "3": program.AddBeer(beerObj); break; } } while (option != "0"); Console.ReadLine(); }