Esempio n. 1
0
        public ActionResult Add(int total, int prodId, int quantity, int imageId)
        {
            HttpResponseMessage prodresponse = GlobalHttp.WebApiClient.GetAsync("Products/" + prodId.ToString()).Result;
            mvcProductModel     product      = prodresponse.Content.ReadAsAsync <mvcProductModel> ().Result;

            mvcCartModel cart = new mvcCartModel();

            cart.CartDetailId = 1;
            cart.CartQuantity = quantity;
            cart.CartTotal    = total;
            cart.ProductID    = prodId;
            cart.ImageId      = imageId;
            cart.ProductName  = product.ProdName;
            HttpResponseMessage response = GlobalHttp.WebApiClient.PostAsJsonAsync("Carts", cart).Result;

            TempData["SuccessMessage"] = "Item Added in to Cart";
            return(RedirectToAction("Index", "Product"));
        }
Esempio n. 2
0
        public ActionResult Update(int prodId, int newQuantity, int oldQuantity, int cartId, int imageId)
        {
            HttpResponseMessage prodresponse = GlobalHttp.WebApiClient.GetAsync("Products/" + prodId.ToString()).Result;
            mvcProductModel     product      = prodresponse.Content.ReadAsAsync <mvcProductModel>().Result;
            int actualQuantity = 0;

            if (newQuantity > oldQuantity)
            {
                actualQuantity        = newQuantity - oldQuantity;
                product.ProdQuantity -= actualQuantity;
            }
            else
            {
                actualQuantity        = oldQuantity - newQuantity;
                product.ProdQuantity += actualQuantity;
            }

            if (product.ProdQuantity < actualQuantity)
            {
                TempData["AlertMessage"] = "Only " + product.ProdQuantity + " are Available!!";
                return(RedirectToAction("Index"));
            }
            else
            {
                //CArt
                HttpResponseMessage cartresponse = GlobalHttp.WebApiClient.GetAsync("Carts/" + cartId.ToString()).Result;
                mvcCartModel        cart         = cartresponse.Content.ReadAsAsync <mvcCartModel>().Result;
                cart.CartQuantity = newQuantity;
                cart.CartTotal    = newQuantity * product.ProdPrice;
                cart.ImageId      = imageId;

                HttpResponseMessage response = GlobalHttp.WebApiClient.PutAsJsonAsync("Carts/" + cart.CartId.ToString(), cart).Result;

                //Product


                HttpResponseMessage productresponse = GlobalHttp.WebApiClient.PutAsJsonAsync("Products/" + product.ProdId.ToString(), product).Result;

                TempData["SuccessMessage"] = "Item Updated Successfully!!";
                return(RedirectToAction("Index"));
            }
        }