Exemplo n.º 1
0
        /*通过专辑的标识从用户的购物车中将这个专辑的数量减少 1,如果用户仅仅剩下一个,那么就删除这一行。*/
        public int RemoveFromCart(int id)
        {
            Maticsoft.BLL.cart item = new Maticsoft.BLL.cart();
            List <Maticsoft.DAL.SqlWhereClass> lssqlwhere = new List <Maticsoft.DAL.SqlWhereClass>();

            Maticsoft.DAL.SqlWhereClass sqlwhere = new Maticsoft.DAL.SqlWhereClass("CartId", "CartId", Maticsoft.DAL.NetOperate.EQ, "'" + ShoppingCartid + "'");
            lssqlwhere.Add(sqlwhere);
            sqlwhere = new Maticsoft.DAL.SqlWhereClass("RecordId", "RecordId", Maticsoft.DAL.NetOperate.EQ, id.ToString());

            var CartItem = item.GetModel(lssqlwhere);

            int itemcount = 0;

            if (CartItem != null)
            {
                if (CartItem.Count > 1)
                {
                    CartItem.Count--;
                    itemcount = CartItem.Count;
                }
                else
                {
                    item.Delete(id);
                }
            }
            return(itemcount);
        }
Exemplo n.º 2
0
        /*
         * 将专辑作为参数加入到购物车中,在 Cart 表中跟踪每个专辑的数量,在这个方法中,我们将会检查是在表中增加一个新行,还是仅仅在用户已经选择的专辑上增加数量。
         */
        public void AddToCart(album album)
        {
            Maticsoft.BLL.cart item = new Maticsoft.BLL.cart();
            List <Maticsoft.DAL.SqlWhereClass> lssqlwhere = new List <Maticsoft.DAL.SqlWhereClass>();

            Maticsoft.DAL.SqlWhereClass sqlwhere = new Maticsoft.DAL.SqlWhereClass("CartId", "CartId", Maticsoft.DAL.NetOperate.EQ, "'" + ShoppingCartid + "'");
            lssqlwhere.Add(sqlwhere);
            sqlwhere = new Maticsoft.DAL.SqlWhereClass("AlbumId", "AlbumId", Maticsoft.DAL.NetOperate.EQ, album.AlbumId.ToString());
            lssqlwhere.Add(sqlwhere);
            var CartItem = item.GetModel(lssqlwhere);

            if (CartItem == null)
            {
                CartItem = new cart
                {
                    AlbumId     = album.AlbumId,
                    CartId      = ShoppingCartid,
                    Count       = 1,
                    DateCreated = DateTime.Now
                };
                item.Add(CartItem);
            }
            else
            {
                CartItem.Count++;
                item.Update(CartItem);
            }
        }
Exemplo n.º 3
0
        public void MigrateCart(string userName)
        {
            Maticsoft.BLL.cart cartbll = new Maticsoft.BLL.cart();
            List <Maticsoft.DAL.SqlWhereClass> lssqlwhere = new List <Maticsoft.DAL.SqlWhereClass>();

            Maticsoft.DAL.SqlWhereClass sqlwhere = new Maticsoft.DAL.SqlWhereClass("CartId", "CartId", Maticsoft.DAL.NetOperate.EQ, "'" + ShoppingCartid + "'");
            lssqlwhere.Add(sqlwhere);
            var cartitem = cartbll.GetModel(lssqlwhere);

            if (cartitem == null)
            {
                return;
            }
            cartitem.CartId = userName;
            cartbll.Update(cartitem);
        }
Exemplo n.º 4
0
        public ActionResult RemoveFromCart(int id)
        {
            var Cart = MvcMusicStore.Models.ShoppingCart.GetCart(this.HttpContext);

            Maticsoft.BLL.album albumbll = new Maticsoft.BLL.album();
            Maticsoft.BLL.cart  cartbll  = new Maticsoft.BLL.cart();
            string albumName             = albumbll.GetModel(cartbll.GetModel(id).AlbumId).Title;
            int    itemCount             = Cart.RemoveFromCart(id);
            var    results = new MvcMusicStore.ViewModels.ShoppingCartRemoveViewModel
            {
                Message   = Server.HtmlEncode(albumName) + " has been removed from your shopping cart.",
                CartTotal = Cart.GetTotal(),
                CartCount = Cart.GetCount(),
                ItemCount = itemCount,
                DeleteId  = id
            };

            return(Json(results));
        }