static public List <Order> GetAllOrders()
 {
     using (var dataBase = new OrdersDB())
     {
         return(dataBase.orders.Include("products").ToList <Order>());
     }
 }
 static public void AddOrder(Order order)
 {
     using (var dataBase = new OrdersDB())
     {
         dataBase.orders.Add(order);
         dataBase.SaveChanges();
     }
 }
 static public List <Order> FindByProduct(string condition)
 {
     using (var dataBase = new OrdersDB())
     {
         var found = dataBase.orders.Include("products")
                     .Where(order => order.num == condition);
         return(found.ToList <Order>());
     }
 }
 static public void DeletOrder(Order order)
 {
     using (var dataBase = new OrdersDB())
     {
         var tempOrder = dataBase.orders.Include("products").SingleOrDefault(temp => temp.num.Equals(order.num));
         dataBase.products.RemoveRange(tempOrder.products);
         dataBase.orders.Remove(tempOrder);
         dataBase.SaveChanges();
     }
 }
 static public List <Order> FindByProductName(string condition)
 {
     using (var dataBase = new OrdersDB())
     {
         var found = dataBase.orders.Include("products")
                     .Where(order => order.products
                            .Where(product => product.productName.Equals(condition)).Count() > 0);
         return(found.ToList <Order>());
     }
 }
 static public void ChangeOrder(Order order)
 {
     using (var dataBase = new OrdersDB())
     {
         dataBase.orders.Attach(order);
         dataBase.Entry(order).State = EntityState.Modified;
         order.products.ForEach
             (product => dataBase.Entry(product).State = EntityState.Modified);
         dataBase.SaveChanges();
     }
 }
 static public List <Order> FindByCost(string condition)
 {
     if (double.TryParse(condition, out double cost))
     {
         using (var dataBase = new OrdersDB())
         {
             var found = dataBase.orders.Include("products")
                         .Where(order => order.products
                                .Where(product => product.cost.Equals(cost)).Count() > 0);
             return(found.ToList <Order>());
         }
     }
     else
     {
         return(new List <Order>());
     }
 }