public ActionResult TimKiemMonAn(string TenMon)
        {
            MonAnDao     mad         = new MonAnDao();
            List <MonAn> danhsachmon = mad.KetQuaTimKiem(TenMon);

            return(PartialView(danhsachmon));
        }
示例#2
0
        public ActionResult addToCart(int maMon, int soLuong)
        {
            var MonAn = new MonAnDao().ViewDetail(maMon);
            var cart  = Session[CommonConstants.CART_SESSION];

            if (cart != null)
            {
                //TH co sp roi
                var list = (List <CartItem>)cart;//ep kieu

                if (list.Exists(x => x.MonAn.MaMon == maMon))
                {
                    foreach (var item in list)
                    {
                        if (item.MonAn.MaMon == maMon)
                        {
                            item.SoLuong += soLuong;
                        }
                    }
                }
                else
                {
                    var item = new CartItem();
                    item.MonAn   = MonAn;
                    item.SoLuong = soLuong;

                    list.Add(item);
                }

                Session[CommonConstants.CART_SESSION] = list;
            }
            else
            {
                //taoj moi 1 doi tuong cart item
                var item = new CartItem();
                item.MonAn   = MonAn;
                item.SoLuong = soLuong;
                var list = new List <CartItem>();

                list.Add(item);
                //gan vao session
                Session[CommonConstants.CART_SESSION] = list;
            }

            return(RedirectToAction("Index"));
        }