static public void AddOrder(Order order) { using (var dataBase = new OrdersDB()) { dataBase.orders.Add(order); dataBase.SaveChanges(); } }
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 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(); } }