// GET: 购物车首页 public ActionResult ShopCarIndex() { //商品图片 ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto(); //查询当前用户与购物车中的商品的收藏关系 ViewBag.UserCollection = CollectionBll.SelectUserCollection(Convert.ToInt32(Session["userid"])); //查询当前用户所有购物车信息 return(View(ShopingCarBll.SelectAllShopCar(Convert.ToInt32(Session["userid"])))); }
/// <summary> /// 加入购物车 /// </summary> /// <param name="GoodsId">商品id</param> /// <param name="ShoppingNum">购买数量</param> /// <returns></returns> public JsonResult AddShopCar(string GoodsId, string ShoppingNum) { //执行新增操作 int erroid = ShopingCarBll.AddShopCar(GoodsId, ShoppingNum, Session["userid"].ToString()); //更新购物车数量 Session["carcount"] = ShopingCarBll.SelectAllShopCar(Convert.ToInt32(Session["userid"])).Count(); //调用新增购物车并返回值 return(Json(erroid, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 商城首页 /// </summary> /// <returns></returns> public ActionResult Index() { //获取导航栏的分类数据 Session["Type"] = TypeTableBll.SelectTypeTable(); //获得所有分类数据 ViewBag.Type = TypeTableBll.SelectAllType(); //获取图片 ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto(); ViewBag.goods_1 = GoodsBll.SelectType1Goods(1).OrderBy(p => p.GoodsHot).Take(8); ViewBag.goods_2 = GoodsBll.SelectType1Goods(2).OrderBy(p => p.GoodsHot).Take(8); ViewBag.goods_3 = GoodsBll.SelectType1Goods(3).OrderBy(p => p.GoodsHot).Take(8); ViewBag.goods_4 = GoodsBll.SelectType1Goods(4).OrderBy(p => p.GoodsHot).Take(8); if (Session["userid"] != null) { Session["carcount"] = ShopingCarBll.SelectAllShopCar(Convert.ToInt32(Session["userid"])).Count(); } return(View(GoodsBll.SelectAllGoods().Where(p => p.IsDelte == 0).ToList())); }
/// <summary> /// 商品详情 /// </summary> /// <param name="goodsid">商品id</param> /// <returns></returns> public ActionResult GoodsDesc(int goodsid) { //商品图片 ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto().Where(p => p.GoodsID == goodsid).ToList(); //商品的所有评价(置顶排序) List <CommentTable> list = CommentBll.SelectGoodsComment(goodsid).OrderByDescending(p => p.IsTop).ToList(); Session["GoodsComment"] = list; //用户是否收藏商品 ViewBag.iscollection = CollectionBll.SelectOneCollection(Convert.ToInt32(Session["userid"]), goodsid); //加载或更新用户购物车数量 if (Session["userid"] != null) { Session["carcount"] = ShopingCarBll.SelectAllShopCar(Convert.ToInt32(Session["userid"])).Count(); } //获取到的该商品的信息 GoodsTable good = GoodsBll.SelectGoodsIdGoods(goodsid); //相关商品的推荐(3条) ViewBag.GetGoods = GoodsBll.SelectGetGoods(good.TID ?? 0).Where(p => p.GoodsID != good.GoodsID).OrderBy(p => Guid.NewGuid()).Take(3).ToList(); Session["GoodsPhoto"] = GoodsPhotoBll.SelectAllGoodsPhoto(); return(View(good)); }