Esempio n. 1
0
        //This methods gets all the cart products either from session or from db
        //based on the authenticity of the user and displays them.
        public ActionResult ShowCart()
        {
            try
            {
                List <CartViewModel> cartViewModels = new List <CartViewModel>();

                if (Session["uname"] != null)
                {
                    cartViewModels = cartServices.ShowCartFromDb(Session["uname"] as string);
                    return(View(cartViewModels));
                }
                if (Session["CartItems"] != null)
                {
                    List <CartViewModel> sessionCartViewModels = Session["CartItems"] as List <CartViewModel>;
                    foreach (var item in sessionCartViewModels)
                    {
                        cartViewModels.Add(item);
                    }
                }
                return(View(cartViewModels));
            }
            catch (Exception e)
            {
                return(View("Error", new HandleErrorInfo(e, "ProductsList", "Product")));
            }
        }