public IHttpActionResult GetProduct(string ID)
 {
     return(Ok(code.GetProduct(ID)));
 }
        public ActionResult AddCart(string id)
        {
            string username = SessionHelper.GetUserSession();

            if (username != null)
            {
                if (SessionHelper.GetCartSession(username) == null)
                {
                    CartSession cartsession = new CartSession();
                    cartsession.sp = code.GetProduct(id);

                    //kiem tra coi co khuyen mai hay k
                    if (cartsession.sp.MAKHUYENMAI != 0)
                    {
                        var    km  = pro.GetPromotion(cartsession.sp.MAKHUYENMAI.ToString());
                        double gia = (double)(cartsession.sp.DONGIABAN * (100 - km.NOIDUNG)) / 100;
                        cartsession.sp.DONGIABAN = gia;
                    }
                    cartsession.soluong = 1;
                    cartsession.daxoa   = false;
                    List <CartSession> cartsessionlist = new List <CartSession>();
                    cartsessionlist.Add(cartsession);
                    SessionHelper.SetCartSession(username, cartsessionlist);
                }
                else
                {
                    CartSession cartsession = new CartSession();
                    cartsession.sp = code.GetProduct(id);

                    //kiem tra coi co khuyen mai hay k
                    if (cartsession.sp.MAKHUYENMAI != 0)
                    {
                        var    km  = pro.GetPromotion(id);
                        double gia = (double)(cartsession.sp.DONGIABAN * (100 - km.NOIDUNG)) / 100;
                        cartsession.sp.DONGIABAN = gia;
                    }

                    cartsession.soluong = 1;
                    cartsession.daxoa   = false;

                    List <CartSession> cartsessionlist = SessionHelper.GetCartSession(username);
                    int i = code.Checkexistproduct(cartsession, cartsessionlist);
                    if (i == -1)
                    {
                        cartsessionlist.Add(cartsession);
                    }
                    else
                    {
                        cartsessionlist[i].soluong++;
                    }

                    SessionHelper.SetCartSession(username, cartsessionlist);
                }
            }
            else
            {
                if (SessionHelper.GetCartSession("cart") == null)
                {
                    CartSession cartsession = new CartSession();
                    cartsession.sp = code.GetProduct(id);
                    //kiem tra coi co khuyen mai hay k
                    if (cartsession.sp.MAKHUYENMAI != 0)
                    {
                        var    km  = pro.GetPromotion(id);
                        double gia = (double)(cartsession.sp.DONGIABAN * (100 - km.NOIDUNG)) / 100;
                        cartsession.sp.DONGIABAN = gia;
                    }

                    cartsession.soluong = 1;
                    cartsession.daxoa   = false;

                    List <CartSession> cartsessionlist = new List <CartSession>();
                    cartsessionlist.Add(cartsession);
                    SessionHelper.SetCartSession("cart", cartsessionlist);
                }
                else
                {
                    CartSession cartsession = new CartSession();
                    cartsession.sp = code.GetProduct(id);
                    //kiem tra coi co khuyen mai hay k
                    if (cartsession.sp.MAKHUYENMAI != 0)
                    {
                        var    km  = pro.GetPromotion(id);
                        double gia = (double)(cartsession.sp.DONGIABAN * (100 - km.NOIDUNG)) / 100;
                        cartsession.sp.DONGIABAN = gia;
                    }


                    cartsession.soluong = 1;
                    cartsession.daxoa   = false;

                    List <CartSession> cartsessionlist = SessionHelper.GetCartSession("cart");
                    int i = code.Checkexistproduct(cartsession, cartsessionlist);
                    if (i == -1)
                    {
                        cartsessionlist.Add(cartsession);
                    }
                    else
                    {
                        cartsessionlist[i].soluong++;
                    }

                    SessionHelper.SetCartSession("cart", cartsessionlist);
                }
            }

            //return Content("<script language='javascript' type='text/javascript'>alert('Thêm giỏ hàng thành công !');</script>");
            return(RedirectToAction("CartContent", "Cart"));
        }