// GET: ShopCar public ActionResult Index() { HomeViewModel homeViewModel = new HomeViewModel(); homeViewModel.ShopCars = ShopCarService.GetEntities(s => true); return(View(homeViewModel)); }
public void addShopCar() { int goodid = int.Parse(Request.QueryString["id"].ToString()); // good = GoodService.GetGoodMsg(id); //return good; //获取用户id int userid; userid = UserService.getUserIdByPhone(getUserName()); if (userid == 0) { userid = UserService.getUserIdByEmail(getUserName()); } int buytime = 1; //添加之前应先检索购物车中是否存在此商品 if (ShopCarService.judgeShopCar(userid, goodid) == false) { Response.Write("<script>alert('亲,商品已在购物车中!');location.href='Index.aspx';</script>"); } else { //添加至购物车表 ShopCarService.addShopCar(userid, goodid, buytime); Response.Write("<script>alert('添加购物车成功!');location.href='Index.aspx';</script>"); } }
public void deleteShopCar() { int shopcarid = int.Parse(Request.QueryString["id"].ToString()); int userid; userid = UserService.getUserIdByPhone(getUserName()); if (userid == 0) { userid = UserService.getUserIdByEmail(getUserName()); } //添加至购物车表 ShopCarService.deleteShopCar(shopcarid); Response.Write("<script>alert('删除该商品成功!');location.href='PersonalShopCar.aspx';</script>"); }
//返回购物车列表 public List <ShopCar> getShopCarList() { int userid; userid = UserService.getUserIdByPhone(getUserName()); if (userid == 0) { userid = UserService.getUserIdByEmail(getUserName()); } //List<ShopCar> shopcars = new List<ShopCar>(); shopcars = ShopCarService.getAllShopCarByUserId(userid); return(shopcars); }
public ShopCar updateShopCar() { int shopid_temp = int.Parse(Request.QueryString["shopid"].ToString()); int buytime_temp = int.Parse(Request.Params["time"]); //获取用户id int userid; userid = UserService.getUserIdByPhone(getUserName()); if (userid == 0) { userid = UserService.getUserIdByEmail(getUserName()); } ShopCarService.updateShopCar(shopid_temp, userid, buytime_temp); shopcar = ShopCarService.getShopCarByShopCarId(shopid_temp); return(shopcar); }
/// <summary> /// 加入购物车 /// </summary> /// <param name="procode">商品ID</param> /// <param name="qty">加入商品的数量</param> /// <returns></returns> public ActionResult AddShopCar(string procode, int qty) { ShoppingCart shopCart = new ShoppingCart(); shopCart.CusId = 1;//用户的ID shopCart.ProCode = procode; shopCart.Qty = qty; shopCart.CreateTime = DateTime.Now; try { bool zt = ShopCarService.Add(shopCart); var msg = zt ? 1 : 0; return(Content("商品添加成功!")); } catch (Exception) { return(Content("此商品已存在,请到购物车编辑!")); } }