Пример #1
0
 static public List <Order> GetAllOrders()
 {
     using (var dataBase = new OrdersDB())
     {
         return(dataBase.orders.Include("products").ToList <Order>());
     }
 }
Пример #2
0
 static public void AddOrder(Order order)
 {
     using (var dataBase = new OrdersDB())
     {
         dataBase.orders.Add(order);
         dataBase.SaveChanges();
     }
 }
Пример #3
0
 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>());
     }
 }
Пример #4
0
 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();
     }
 }
Пример #5
0
 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>());
     }
 }
Пример #6
0
 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();
     }
 }
Пример #7
0
 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>());
     }
 }