Ejemplo n.º 1
0
        protected void BuyCheck(object sender, CommandEventArgs e)
        {
            int discountcode = 0;

            if (User.Identity.IsAuthenticated == false)
            {
                Response.Redirect("~/Login.aspx");
            }
            else
            {
                ShopCart mycart = new ShopCart();
                mycart.BookID      = Convert.ToInt32(e.CommandArgument);
                mycart.SessionUser = User.Identity.Name;
                foreach (Book x in db2.Books)
                {
                    if (x.BookID == mycart.BookID)
                    {
                        mycart.ISBN      = x.ISBN;
                        mycart.BookTitle = x.Title;
                        mycart.Price     = Math.Round((double)x.Price, 2);
                        mycart.Discount  = x.BookDiscount;
                    }
                }
                if (User.IsInRole("Silver"))
                {
                    discountcode = 2;
                }
                else if (User.IsInRole("Gold"))
                {
                    discountcode = 3;
                }
                else if (User.IsInRole("Platinium"))
                {
                    discountcode = 5;
                }
                foreach (Discount d in db2.Discounts)
                {
                    if (d.DiscountID == discountcode)
                    {
                        mycart.Discount += d.DiscountAmt;
                    }
                }
                foreach (ShopCart y in db2.ShopCarts)
                {
                    if (y.BookID == mycart.BookID)
                    {
                        y.Quantity++;
                        y.Subtotal = y.Quantity * y.Price * (100 - y.Discount) / 100;
                        y.Subtotal = Math.Round(y.Subtotal, 2);
                        db2.SaveChanges();
                        return;
                    }
                }
                mycart.Quantity = 1;
                mycart.Subtotal = mycart.Price * mycart.Quantity * (100 - mycart.Discount) / 100;
                mycart.Subtotal = Math.Round(mycart.Subtotal, 2);
                db2.ShopCarts.Add(mycart);
                db2.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public void DeleteOrder(int index)
        {
            string          UserN      = User.Identity.Name;
            List <ShopCart> myshopcart = new List <ShopCart>();

            foreach (ShopCart sc in db2.ShopCarts)
            {
                if (sc.SessionUser == UserN)
                {
                    myshopcart.Add(sc);
                }
            }
            ShopCart cartitem = myshopcart[index];

            db2.ShopCarts.Remove(cartitem);
            db2.SaveChanges();

            myshopcart = db2.ShopCarts.ToList <ShopCart>();
            grandtotal = 0;
            foreach (ShopCart x in myshopcart)
            {
                grandtotal += x.Subtotal;
                double temp = Math.Round((x.Discount / 100 * x.Quantity * x.Price), 2);
                discounts += temp;
            }
            Label2.Text = "Total Savings : $" + discounts.ToString();
            Label1.Text = "Grand Total : $" + grandtotal.ToString();
        }