Beispiel #1
0
        public ActionResult CheckOut(string couponCode)
        {
            Cart cart = Session["Cart"] as Cart;

            if (couponCode != null)
            {
                Session["Codee"] = null;
                Session["Codee"] = couponCode;
            }
            if (Session["Codee"] != null)
            {
                var coupon = _couponServices.GetById(Session["Codee"]);
                if (coupon != null)
                {
                    decimal total = (decimal)cart.Total_Money();
                    total -= (total * coupon.Discount) / 100;

                    ViewBag.GrandTotal = total.ToString("#,###");
                    return(View(cart));
                }
                else
                {
                    ViewBag.errormg = "Mã giảm giá đã hết hạn hoặc không tồn tại!";
                    decimal total = (decimal)cart.Total_Money();

                    ViewBag.GrandTotal = total.ToString("#,###");
                    return(View(cart));
                }
            }
            else
            {
                decimal total = (decimal)cart.Total_Money();

                ViewBag.GrandTotal = total.ToString("#,###");
                return(View(cart));
            }
        }
Beispiel #2
0
 public ActionResult Index(string couponCode)
 {
     if (couponCode != null)
     {
         Session[Constant.Code] = couponCode;
     }
     if (Session[Constant.Code] != null)
     {
         var coupon = _coupon.GetById(Session[Constant.Code]);
         if (coupon != null)
         {
             var cart = Session[Constant.Cart];
             var list = new List <CartItem>();
             if (cart != null)
             {
                 list = (List <CartItem>)cart;
             }
             decimal total = 0m;
             foreach (var item in list)
             {
                 total += item.Total;
             }
             total -= (total * coupon.Discount) / 100;
             ViewBag.GrandTotal = total.ToString("#,###");
             return(View(list));
         }
         else
         {
             ViewBag.errormg = "Mã giảm giá đã hết hạn hoặc không tồn tại!";
             var cart = Session[Constant.Cart];
             var list = new List <CartItem>();
             if (cart != null)
             {
                 list = (List <CartItem>)cart;
             }
             decimal total = 0m;
             foreach (var item in list)
             {
                 total += item.Total;
             }
             ViewBag.GrandTotal = total.ToString("#,###");
             return(View(list));
         }
     }
     else
     {
         var cart = Session[Constant.Cart];
         var list = new List <CartItem>();
         if (cart != null)
         {
             list = (List <CartItem>)cart;
         }
         decimal total = 0m;
         foreach (var item in list)
         {
             total += item.Total;
         }
         ViewBag.GrandTotal = total.ToString("#,###");
         return(View(list));
     }
 }