コード例 #1
0
ファイル: CartController.cs プロジェクト: Faimous/MyShop
        private void addToCart(int pId)
        {
            // check if product is valid
            ProductTable product = Database.Products.FirstOrDefault(p => p.Id == pId);

            if (product != null && product.UnitsInStock > 0)
            {
                // check if product already existed
                ShoppingCartTable cart = Database.ShoppingCartDatas.FirstOrDefault(c => c.PID == pId);
                if (cart != null)
                {
                    cart.Quantity++;
                }
                else
                {
                    cart = new ShoppingCartTable
                    {
                        PName     = product.ProductName,
                        PID       = product.Id,
                        UnitPrice = (decimal)product.UnitPrice,
                        Quantity  = 1
                    };

                    Database.ShoppingCartDatas.Add(cart);
                }
                Database.SaveChanges();
            }
        }
コード例 #2
0
 public async void DeleShopping(ShoppingCartTable _shoppingCartTable)
 {
     try
     {
     }
     catch {
     }
 }
コード例 #3
0
ファイル: CartController.cs プロジェクト: Faimous/MyShop
        public JsonResult QuanityChange(int type, int pId)
        {
            using (var db = new _DatabseContextShop())
            {
                ShoppingCartTable product = db.ShoppingCartDatas.FirstOrDefault(p => p.PID == pId);
                if (product == null)
                {
                    return(Json(new { d = "0" }));
                }

                ProductTable actualProduct = db.Products.FirstOrDefault(p => p.Id == pId);
                int?         quantity;
                // if type 0, decrease quantity
                // if type 1, increase quanity
                switch (type)
                {
                case 0:
                    product.Quantity--;
                    actualProduct.UnitsInStock++;
                    break;

                case 1:
                    product.Quantity++;
                    actualProduct.UnitsInStock--;
                    break;

                case -1:
                    actualProduct.UnitsInStock += product.Quantity;
                    product.Quantity            = 0;
                    break;

                default:
                    return(Json(new { d = "0" }));
                }

                if (product.Quantity == 0)
                {
                    db.ShoppingCartDatas.Remove(product);
                    quantity = 0;
                }
                else
                {
                    quantity = product.Quantity;
                }

                db.SaveChanges();
                return(Json(new { d = quantity }));
            }
        }
コード例 #4
0
 public void UpdateShoppingQty(ShoppingCartTable _shoppingCartTable)
 {
     try {
         ShoppingCartTable shoppingCartTable;
         var Shoppingtable = _repositoryShop.GetAll()
                             .Where(c => c.CommodityId == _shoppingCartTable.CommodityId &&
                                    c.FounderId == _shoppingCartTable.FounderId &&
                                    c.Specification == _shoppingCartTable.Specification)
                             .ToList();
         // 如果购物车中没有此id就创建
         if (Shoppingtable.Count == 0)
         {
             _shoppingCartTable.TotalCost = _shoppingCartTable.Qty * _shoppingCartTable.UnitPrice;
             _repositoryShop.Insert(_shoppingCartTable);
         }
         else
         {
             //如果数量等于0就将其删掉
             if (_shoppingCartTable.Qty == 0)
             {
                 _repositoryShop.Delete(_shoppingCartTable);
             }
             else
             {
                 // 加一
                 shoppingCartTable           = new ListResultDto <ShoppingCartTable>(ObjectMapper.Map <List <ShoppingCartTable> >(Shoppingtable)).Items[0];
                 shoppingCartTable.Qty       = _shoppingCartTable.Qty + shoppingCartTable.Qty;
                 shoppingCartTable.TotalCost = shoppingCartTable.Qty * shoppingCartTable.UnitPrice;
                 _repositoryShop.Update(shoppingCartTable);
             }
         }
     }
     catch
     {
     }
 }
コード例 #5
0
 // Displays your shopping cart
 private void DisplayOrders()
 {
     OrderBasketPage = new ShoppingCartTable(OrderLine.all(), Workshop);
 }