/// <summary> /// 登陆情况下的购物车 /// </summary> private void OnlineCart() { int productId; if (Int32.TryParse(Request["item"], out productId)) { Books b = bookbll.QuerySingle(productId); if (b != null) { // db 判断购物车中是否已存在该商品 Cart exist = cartbll.QuerySingle(new { BookId = productId, __o = "and", UserId = CurrentUser.Id }); if (exist != null) { // 如果已经存在 exist.Count += 1; cartbll.Update(exist); } else { // 创建一个购物车对象加入到购物车表中 exist = new Cart(); exist.BookId = b.Id; // cart是否可能已经存在 exist.UserId = CurrentUser.Id; exist.Count = 1; cartbll.Insert(exist); } } } CartList = cartbll.GetCartInfos(CurrentUser.Id); }