// GET MEALS FUNCTION UPDATED BY CARLOS protected async Task GetMeals(string kitchen_id) { // Console.WriteLine("kitchen_name: " + kitchen_name); NoMealsLabel.IsVisible = false; var request = new HttpRequestMessage(); request.RequestUri = new Uri("https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/itemsByBusiness/" + kitchen_id); request.Method = HttpMethod.Get; var client = new HttpClient(); HttpResponseMessage response = await client.SendAsync(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { HttpContent content = response.Content; var mealsString = await content.ReadAsStringAsync(); JObject meals = JObject.Parse(mealsString); String todaysDate = DateTime.Now.ToString("MM/dd/yyyy"); Console.WriteLine("This is what you see in meals" + meals); string items = await response.Content.ReadAsStringAsync(); ServingFreshBusinessItems data = new ServingFreshBusinessItems(); data = JsonConvert.DeserializeObject <ServingFreshBusinessItems>(items); if (todaysDate[0] == '0') { todaysDate = todaysDate.Substring(1); } todaysDate = todaysDate.Replace("/0", "/"); this.Meals.Clear(); NoMealsLabel.IsVisible = false; for (int i = 0; i < data.result.result.Count; i++) { NoMealsLabel.IsVisible = false; this.Meals.Add(new MealsModel() { imageString = data.result.result[i].item_photo, title = data.result.result[i].item_name, price = data.result.result[i].item_price.ToString(), description = "description", kitchen_id = data.result.result[i].itm_business_uid, id = data.result.result[i].item_uid, qty = 0 } ); } mealsListView.ItemsSource = Meals; } }
private async void GetData(List <string> types, List <string> b_uids) { GetItemPost post = new GetItemPost(); post.type = types; post.ids = b_uids; var client = new HttpClient(); var getItemsString = JsonConvert.SerializeObject(post); var getItemsStringMessage = new StringContent(getItemsString, Encoding.UTF8, "application/json"); var request = new HttpRequestMessage(); request.Method = HttpMethod.Post; request.Content = getItemsStringMessage; var httpResponse = await client.PostAsync("https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/getItems", getItemsStringMessage); string responseStr = await httpResponse.Content.ReadAsStringAsync(); //ServingFreshBusinessItems data = JsonConvert.DeserializeObject<ServingFreshBusinessItems>(responseStr); //var response = await client.GetAsync("https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/getItems/" + weekDay); //var d = await client.GetStringAsync("https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/getItems/" + weekDay); //Console.WriteLine("This is the data received for items = " + d); //Console.WriteLine(response.IsSuccessStatusCode); Console.WriteLine(responseStr); if (responseStr != null) { //string result = response.Content.ReadAsStringAsync().Result; data = JsonConvert.DeserializeObject <ServingFreshBusinessItems>(responseStr); // COMMENT THE FOLLOWING LINE OF CODE AS (CHANGE 2) // datagrid = new List<ItemModel>(); this.datagrid.Clear(); int n = data.result.Count; int j = 0; if (n == 0) { this.datagrid.Add(new ItemsModel() { height = this.Width / 2 + 25, width = this.Width / 2 - 25, imageSourceLeft = "", quantityLeft = 0, itemNameLeft = "", itemPriceLeft = "$ " + "", isItemLeftVisiable = false, isItemLeftEnable = false, quantityL = 0, imageSourceRight = "", quantityRight = 0, itemNameRight = "", itemPriceRight = "$ " + "", isItemRightVisiable = false, isItemRightEnable = false, quantityR = 0 }); } if (isAmountItemsEven(n)) { for (int i = 0; i < n / 2; i++) { this.datagrid.Add(new ItemsModel() { height = this.Width / 2 + 25, width = this.Width / 2 - 25, imageSourceLeft = data.result[j].item_photo, item_uidLeft = data.result[j].item_uid, itm_business_uidLeft = data.result[j].itm_business_uid, quantityLeft = 0, itemNameLeft = data.result[j].item_name, itemPriceLeft = "$ " + data.result[j].item_price.ToString(), isItemLeftVisiable = true, isItemLeftEnable = true, quantityL = 0, imageSourceRight = data.result[j + 1].item_photo, item_uidRight = data.result[j + 1].item_uid, itm_business_uidRight = data.result[j + 1].itm_business_uid, quantityRight = 0, itemNameRight = data.result[j + 1].item_name, itemPriceRight = "$ " + data.result[j + 1].item_price.ToString(), isItemRightVisiable = true, isItemRightEnable = true, quantityR = 0 }); j = j + 2; } } else { for (int i = 0; i < n / 2; i++) { this.datagrid.Add(new ItemsModel() { height = this.Width / 2 + 25, width = this.Width / 2 - 25, imageSourceLeft = data.result[j].item_photo, item_uidLeft = data.result[j].item_uid, itm_business_uidLeft = data.result[j].itm_business_uid, quantityLeft = 0, itemNameLeft = data.result[j].item_name, itemPriceLeft = "$ " + data.result[j].item_price.ToString(), isItemLeftVisiable = true, isItemLeftEnable = true, quantityL = 0, imageSourceRight = data.result[j + 1].item_photo, item_uidRight = data.result[j + 1].item_uid, itm_business_uidRight = data.result[j + 1].itm_business_uid, quantityRight = 0, itemNameRight = data.result[j + 1].item_name, itemPriceRight = "$ " + data.result[j + 1].item_price.ToString(), isItemRightVisiable = true, isItemRightEnable = true, quantityR = 0 }); j = j + 2; } this.datagrid.Add(new ItemsModel() { height = this.Width / 2 + 25, width = this.Width / 2 - 25, imageSourceLeft = data.result[j].item_photo, item_uidLeft = data.result[j].item_uid, itm_business_uidLeft = data.result[j].itm_business_uid, quantityLeft = 0, itemNameLeft = data.result[j].item_name, itemPriceLeft = "$ " + data.result[j].item_price.ToString(), isItemLeftVisiable = true, isItemLeftEnable = true, quantityL = 0, imageSourceRight = "", quantityRight = 0, itemNameRight = "", itemPriceRight = "$ " + "", isItemRightVisiable = false, isItemRightEnable = false, quantityR = 0 }); } } }