コード例 #1
0
        public void Delete(Guid Id)
        {
            var prod = GetById(Id);

            _dbContext.Products.Remove(prod);
            _dbContext.SaveChanges();
        }
コード例 #2
0
        public async void AddToCart(Product product, int amount)
        {
            var shoppingCartItem = _dbContext.ShoppingCartItems.Where(x => x.Product.ProductId == product.ProductId && x.ShoppingCartId == _ShoppingCartId).FirstOrDefault();


            if (shoppingCartItem == null)
            {
                var Shoppingcartitem = new ShoppingCartItem
                {
                    Amount         = amount,
                    Product        = product,
                    ShoppingCartId = _ShoppingCartId
                };


                await _dbContext.ShoppingCartItems.AddAsync(Shoppingcartitem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            _dbContext.SaveChanges();
        }
コード例 #3
0
        public void CreateOrder(Order order)
        {
            order.PlacedAt = DateTime.Now;
            _dbContext.Orders.Add(order);
            var cartItems = _shoppingCart.ShoppingCartItems;

            foreach (var item in cartItems)
            {
                var orderInfo = new OrderInfo
                {
                    Amount    = item.Amount,
                    OrderId   = order.OrderId,
                    ProductId = item.Product.ProductId,
                    Price     = item.Product.Price
                };

                _dbContext.OrderDetails.Add(orderInfo);
                _dbContext.SaveChanges();
            }
        }