private static void UpdateLocation(BBearContext dbContext, Order order)
        {
            dbContext.Location.Find(order.LocationID).Inventory.Where(x => x.Product.ProductName == "Bear").First().Quantity--;
            foreach (Bear bear in order.bears)
            {
                foreach (Training t in bear.upgrades)
                {
                    dbContext.Location.Find(order.LocationID).Inventory.Where(x => x.Product.ProductName == t.Name).First().Quantity--;
                }
            }

            try
            {
                dbContext.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                dbContext.Location.Find(order.LocationID).Inventory.Where(x => x.Product.ProductName == "Bear").First().Quantity++;
                foreach (Bear bear in order.bears)
                {
                    foreach (Training t in bear.upgrades)
                    {
                        dbContext.Location.Find(order.LocationID).Inventory.Where(x => x.Product.ProductName == t.Name).First().Quantity++;
                    }
                }

                Console.WriteLine(ex.Message);
            }
        }
        private static void UpdateCustomer(BBearContext dbContext, Order order)
        {
            dbContext.Customer.Find(order.CustomerID).DefLocationId = order.LocationID;
            dbContext.Customer.Find(order.CustomerID).LastOrder     = DateTime.Now;

            try
            {
                dbContext.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                dbContext.Customer.Find(order.CustomerID).DefLocationId = null;
                dbContext.Customer.Find(order.CustomerID).LastOrder     = null;
                Console.WriteLine(ex.Message);
            }
        }
        private static void AddOrder(BBearContext dbContext, Order order)
        {
            var newOrders = new Orders();

            newOrders.PriceTag   = Convert.ToDecimal(order.Price);
            newOrders.LocationId = order.LocationID;
            newOrders.CustomerId = order.CustomerID;
            newOrders.CreatedAt  = DateTime.Now;
            foreach (Bear bear in order.bears)
            {
                SoldBears b = new SoldBears();
                HashSet <SoldTraining> hst = new HashSet <SoldTraining>();
                foreach (Training training in bear.upgrades)
                {
                    SoldTraining st = new SoldTraining();
                    Product      p  = dbContext.Product.Where(x => x.ProductName == training.Name).First();
                    st.ProductId = p.ProductId;
                    hst.Add(st);
                }
                b.SoldTraining = hst;
                newOrders.SoldBears.Add(b);
            }



            dbContext.Add(newOrders);

            try
            {
                dbContext.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                dbContext.Orders.Remove(newOrders);
                Console.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Delete a order by ID. Any reviews associated to it will also be deleted.
        /// </summary>
        /// <param name="orderId">The ID of the order</param>
        //public void DeleteOrder(int orderId)
        //{
        //    _logger.LogInformation("Deleting order with ID {orderId}", orderId);
        //    Order entity = _dbContext.Order.Find(orderId);
        //    _dbContext.Remove(entity);
        //}



        /// <summary>
        /// Persist changes to the data source.
        /// </summary>
        public void Save()
        {
            _logger.LogInformation("Saving changes to the database");
            _dbContext.SaveChanges();
        }