Exemple #1
0
        public async Task <ActionResult> AddProduct(int productId, int quantity = 1)
        {
            OperationDetails result;

            using (BasketServiceClient client = new BasketServiceClient())
            {
                string basketId;
                if ((string)Session["BasketID"] == null)
                {
                    basketId = await Task.Run(() => client.GenerateBasketId());

                    Session["BasketID"] = basketId;
                }
                else
                {
                    basketId = (string)Session["BasketID"];
                }

                result = await Task.Run(() => client.AddProduct(basketId, productId, quantity));

                if (result.Status == OperationDetails.Statuses.Success)
                {
                    Session["BasketItems"] = await Task.Run(() => client.GetBasketItems(basketId));
                }
            }

            return(Json(result.Status.ToString(), JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public async Task <ActionResult> RemoveProduct(int productId, int quantity = 1)
        {
            OperationDetails result;
            var basketId = (string)Session["BasketID"];

            using (BasketServiceClient client = new BasketServiceClient())
            {
                result = await Task.Run(() => client.RemoveProduct(basketId, productId, quantity));

                if (result.Status == OperationDetails.Statuses.Success)
                {
                    Session["BasketItems"] = await Task.Run(() => client.GetBasketItems(basketId));
                }
            }

            return(Json(result.Status.ToString(), JsonRequestBehavior.AllowGet));
        }