Beispiel #1
0
        public void AddToCart(Clothes clothes, int amount)
        {
            var shoppingCartItem = _atDbContext.ShopppingCartItems.SingleOrDefault(
                s => s.Clothes.ClothesId == clothes.ClothesId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Clothes        = clothes,
                    Amount         = amount
                };

                _atDbContext.ShopppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }

            _atDbContext.SaveChanges();
        }
Beispiel #2
0
        public void CreateOrder(Order order)
        {
            order.OrderPlaced = DateTime.Now;
            order.OrderTotal  = _shoppingCart.GetShoppingCartTotal();
            _atDbContext.Orders.Add(order);
            _atDbContext.SaveChanges();

            var shoppingCartItems = _shoppingCart.GetShoppingCartItems();

            foreach (var shoppingCartItem in shoppingCartItems)
            {
                var orderDetail = new OrderDetail
                {
                    Amount    = shoppingCartItem.Amount,
                    Price     = shoppingCartItem.Clothes.Price,
                    ClothesId = shoppingCartItem.Clothes.ClothesId,
                    OrderId   = order.OrderId
                };

                _atDbContext.OrderDetails.Add(orderDetail);
            }

            _atDbContext.SaveChanges();
        }