예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // Fetch cart items from DB
                //using (CartRepository _repository = new CartRepository())
                CartItem _repository = new CartItem();
                {
                    List <CartItemEntity> cartItems = _repository.GetCartItems();

                    // Calculate total amount
                    double totalAmount = _repository.GetTotal();
                    // Calculate total quantity
                    double totalQuantity = _repository.GetCount();

                    // Bind cart items to Repeater control
                    CartItemsRepeater.DataSource = cartItems;
                    CartItemsRepeater.DataBind();

                    // Set the footer part (total)
                    LblSubQuantity.Text = totalQuantity > 1 ? totalQuantity + " items" : totalQuantity + " item";
                    LblSubAmount.Text   = totalAmount.ToString();
                }
            }
        }
예제 #2
0
        public IActionResult Index()
        {
            try
            {
                var customer = JsonConvert.DeserializeObject <Models.Customer>(HttpContext.Session.GetString("CustomerSession"));
                ViewBag.IsLogged = "true";
                ViewBag.Name     = customer.Name;
                List <Item> objList = CartItem.GetCartItems(customer.Id, _connection);
                if ((objList != null) && (!objList.Any()))
                {
                    ViewBag.Count = 0;

                    ViewBag.Total = 0;
                }
                else
                {
                    double total = 0;
                    foreach (var item in objList)
                    {
                        ViewBag.Count = 1;
                        // Console.WriteLine("Amount is {0} and type is {1}", money.amount, money.type);
                        total = item.Price + total;
                    }

                    ViewBag.Total = total;
                }


                return(View(objList));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Index", "Customer1"));
            }
        }