// GET: CartController public async Task <IActionResult> Index() { List <Cart> cartitems = new List <Cart>(); HttpClient client = obj.CartItems(); HttpResponseMessage res = await client.GetAsync("api/Cart"); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; cartitems = JsonConvert.DeserializeObject <List <Cart> >(result); } return(View(cartitems)); }
public IActionResult GetCartItems(Cart cart) { HttpClient client = obj.CartItems(); var postTask = client.PostAsJsonAsync <Cart>($"api/Cart", cart); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } return(Content("Not Working")); }