Exemple #1
0
        public async Task <IActionResult> Index()
        {
            List <Item>         items  = new List <Item>();
            HttpClient          client = obj.ItemDetails();
            HttpResponseMessage res    = await client.GetAsync("api/Item");

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                items = JsonConvert.DeserializeObject <List <Item> >(result);
            }
            return(View(items));
        }
        // GET: CartController/Edit/5
        public async Task <IActionResult> Edit(int id)
        {
            Cart                cart   = new Cart();
            HttpClient          client = obj.CartItems();
            HttpResponseMessage res    = await client.GetAsync("api/Cart/" + id);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                cart = JsonConvert.DeserializeObject <Cart>(result);
            }
            var itemid = cart.ItemId;

            Item                item    = new Item();
            HttpClient          client1 = obj.ItemDetails();
            HttpResponseMessage res1    = await client1.GetAsync("api/Item/" + itemid);

            if (res1.IsSuccessStatusCode)
            {
                var result = res1.Content.ReadAsStringAsync().Result;
                item = JsonConvert.DeserializeObject <Item>(result);
            }

            cart.item = item;

            return(View(cart));
        }