Example #1
0
        public void PopulateBasketAndProductKeys(int basketId, int productId, BasketItem basketItem)
        {
            Basket  basket  = context.Baskets.Find(basketId);
            Product product = context.Products.Find(productId);

            if (product.BasketItems == null && basket.BasketItems == null)
            {
                basket.BasketItems  = new List <BasketItem>();
                product.BasketItems = new List <BasketItem>();
            }

            basket.BasketItems.Add(basketItem);
            product.BasketItems.Add(basketItem);

            context.SaveChanges();
        }
        public void AddOrder(int basketId, Order order)
        {
            Basket basket = context.Baskets.Find(basketId);

            if (basket.Orders == null)
            {
                basket.Orders = new List <Order>();
            }
            basket.Orders.Add(order);

            context.SaveChanges();
        }
        public void CreateBasket(int userId, Basket basket)
        {
            User user = context.Users.Find(userId);

            if (user.Baskets == null)
            {
                user.Baskets = new List <Basket>();
            }

            user.Baskets.Add(basket);

            context.SaveChanges();
        }
        public void AddUser(User user)
        {
            context.Users.Add(user);

            context.SaveChanges();
        }