コード例 #1
0
        public async Task <IActionResult> AddItemToCartTest(int Id)
        {
            List <Product> products = new List <Product>();
            Product        cartItem = new Product();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://localhost:44374/api/Products/GetProduct/" + Id))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    cartItem = JsonConvert.DeserializeObject <Product>(apiResponse);
コード例 #2
0
        public async Task <IActionResult> AddItemToCart(Product model)
        {
            Product cartModel = new Product();

            using (var httpClient = new HttpClient())
            {
                AddToCartModel _AddToCArtModel = new AddToCartModel
                {
                    Id       = model.Id,
                    Username = this.User.Identity.Name
                };
                Username = _AddToCArtModel.Username;
                StringContent content = new StringContent(JsonConvert.SerializeObject(_AddToCArtModel), Encoding.UTF8, "application/json");
                using (var response = await httpClient.PostAsync("https://localhost:44374/api/Cart/PostOrder", content))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    // cartModel = JsonConvert.DeserializeObject<string>(apiResponse);
                }
            }
            return(RedirectToAction(nameof(Index)));
        }