Example #1
0
        /// <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);
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int item;

            Int32.TryParse(Request["item"], out item);
            if (item == 0)
            {
                // 没有找到资源
                throw new HttpException(404, "Not Found");
            }

            // 调用业务层方法查询实体
            CurrentBook = bll.QuerySingle(item);
            if (CurrentBook == null)
            {
                // 没有找到资源
                throw new HttpException(404, "Not Found");
            }
        }