public bool SaveNewOrder(Order order) { using (var db = new DbContextClass()) { db.Orders.Add(order); return(db.SaveChanges() > 0); } }
public bool DeleteCustomer(Customer customer) { using (var db = new DbContextClass()) { db.Customers.Remove(customer); return(db.SaveChanges() > 0); } }
public bool CheckoutCustomer(Customer customer, Order order) { using (var db = new DbContextClass()) { customer.CurrentOrder = null; order.date = DateTime.Now; if (db.Orders.Contains(order)) { db.Remove(order); db.Update(customer); // db.Database.ExecuteSqlRaw("UPDATE dbo.Customers SET CurrentOrderOrderId = null WHERE CustomerId = '" + customer.CustomerId + "'"); db.SaveChanges(); // Console.WriteLine("change? :" + ); } db.Add(order); customer.FinishedOrders.Add(order); db.Update(customer); return(db.SaveChanges() > 0); } }
public bool Register(Customer customer) { bool saved = false; using (var db = new DbContextClass()) { db.Customers.Add(customer); saved = db.SaveChanges() > 0; } return(saved); }
// public bool AddPizza(APizza pizza) // { // using (var db = new DbContextClass()) // { // try // { // } // catch (System.Exception) // { // throw; // } // } // } public bool RemovePizzaFromDBOrder(Order order, APizza pizza) { using (var db = new DbContextClass()) { if (!db.Orders.Contains(order)) { return(true); } if (!db.Pizzas.Contains(pizza)) { return(true); } db.Pizzas.Remove(pizza); return(db.SaveChanges() > 0); } }
/// <summary> /// check if customer has an order saved in the db /// if yes, delete that order /// if no, just do nothing /// </summary> /// <param name="customer"></param> /// <returns></returns> internal bool DeleteOrderIfExists(Customer customer) { using (var db = new DbContextClass()) { Order o = null; try { o = db.Orders.Where(o => o.OrderId == db.Customers.Where(c => c.CustomerId == customer.CustomerId).First().CurrentOrder.OrderId).First(); } catch (System.Exception) { customer.CurrentOrder = null; return(true); } customer.CurrentOrder = null; // db.Database.ExecuteSqlRaw("UPDATE dbo.Customers SET CurrentOrderOrderId = null WHERE CustomerId = '" + customer.CustomerId + "'"); db.Update(customer); // db.SaveChanges(); db.Orders.Remove(o); return(db.SaveChanges() > 0); } }
public bool RemoveSizeFromDBPizza(Order order, APizza pizza, Size size) { using (var db = new DbContextClass()) { if (!db.Orders.Contains(order)) { return(true); } if (!db.Pizzas.Contains(pizza)) { return(true); } // if (component.GetType() == size.GetType()) // { // Console.WriteLine("remove a size"); if (!db.Sizes.Contains(size)) { return(true); } // } db.Sizes.Remove(size); return(db.SaveChanges() > 0); } }
public bool RemoveCrustFromDBPizza(Order order, APizza pizza, Crust crust) { using (var db = new DbContextClass()) { if (!db.Orders.Contains(order)) { return(true); } if (!db.Pizzas.Contains(pizza)) { return(true); } // if (component.GetType() == Topping.GetType()) // { // Console.WriteLine("remove a topping"); if (!db.Crusts.Contains(crust)) { return(true); } // } db.Crusts.Remove(crust); return(db.SaveChanges() > 0); } }
public bool SaveCustomerChanges(Customer customer) { using (var db = new DbContextClass()) { if (!db.Orders.Contains(customer.CurrentOrder)) { SaveNewOrder(customer.CurrentOrder); } else { customer.CurrentOrder.Pizzas.ForEach(pizza => { if (!db.Pizzas.Contains(pizza)) { db.Pizzas.Add(pizza); } else { pizza.ToppingList.ForEach(topping => { if (!db.Toppings.Contains(topping)) { db.Toppings.Add(topping); } }); if (!db.Crusts.Contains(pizza.PizzaCrust)) { db.Crusts.Add(pizza.PizzaCrust); } if (!db.Sizes.Contains(pizza.PizzaSize)) { db.Sizes.Add(pizza.PizzaSize); } } }); db.SaveChanges(); } // try // { // // db.DbContextOptionsBuilder.EnableSensitiveDataLogging = true; // db.Orders.Where(o => o.OrderId == customer.CurrentOrder.OrderId).First(); // } // catch (System.Exception e) // { // Console.WriteLine("couldn't find it " + e.Message + "\n" + e.StackTrace); // SaveNewOrder(customer.CurrentOrder); // } try { db.Update(customer.CurrentOrder); db.Update(customer); } catch (Microsoft.EntityFrameworkCore.DbUpdateException e) { // db.Orders.Add(customer.CurrentOrder); // db.Update(customer); Console.WriteLine("an error occurred while saving your changes: " + e.Message + "\n" + e.StackTrace); } catch (System.InvalidOperationException e) { Console.WriteLine("an error occurred while saving your changes: " + e.Message + "\n" + e.StackTrace); } return(db.SaveChanges() > 0); } }