/* #endregion */ /* #region Store Methods */ public Dictionary <Customer, List <Order> > GetAllFinishedOrders() { // customerOrders = new Dictionary<Customer, List<Order>>(); Dictionary <Customer, List <Order> > os = new Dictionary <Customer, List <Order> >(); using (var db = new DbContextClass()) { // db.Orders.EntityType.GetProperty("CustomerId").; db.Customers.Include(c => c.FinishedOrders).ToList().ForEach(c => { // Console.WriteLine("customer? " + c.Username); if (c.FinishedOrders.Count > 0) { foreach (var order in c.FinishedOrders) { db.Entry(order).Reference(o => o.Store).Load(); db.Entry(order).Collection(o => o.Pizzas).Load(); order.Pizzas.ForEach( pizza => { db.Entry(pizza).Reference(p => p.PizzaCrust).Load(); db.Entry(pizza).Reference(p => p.PizzaSize).Load(); db.Entry(pizza).Collection(p => p.ToppingList).Load(); } ); // Console.WriteLine("order? " + order); } } // Console.WriteLine(c.FinishedOrders); os.Add(c, c.FinishedOrders); }); return(os); // orders = db.Database.ExecuteSqlRaw("SELECT * FROM dbo.Orders WHERE CustomerId NOT null"); // db.Orders.Where(o=>o.Property()); } }
public bool Login(string username, string password, out Customer customer) { using (var db = new DbContextClass()) { Customer c = null; try { c = db.Customers.Include(c => c.CurrentOrder) .Where(c => c.Username == username) .Include(c => c.FinishedOrders) .Include(c => c.CurrentOrder.Store) .Include(c => c.CurrentOrder.Pizzas) .First(); if (c.CurrentOrder != null) { c.CurrentOrder.Pizzas.ForEach( pizza => { db.Entry(pizza).Reference(p => p.PizzaCrust).Load(); db.Entry(pizza).Reference(p => p.PizzaSize).Load(); db.Entry(pizza).Collection(p => p.ToppingList).Load(); } ); } if (c.FinishedOrders.Count > 0) { foreach (var order in c.FinishedOrders) { db.Entry(order).Reference(o => o.Store).Load(); db.Entry(order).Collection(o => o.Pizzas).Load(); order.Pizzas.ForEach( pizza => { db.Entry(pizza).Reference(p => p.PizzaCrust).Load(); db.Entry(pizza).Reference(p => p.PizzaSize).Load(); db.Entry(pizza).Collection(p => p.ToppingList).Load(); } ); } } // .Include(c => c.CurrentOrder.Pizzas) // .Include(c => c.CurrentOrder.Pizzas.FirstOrDefault().PizzaSize) // .Include(c => c.CurrentOrder.Pizzas.FirstOrDefault().PizzaCrust) // .Include(c => c.CurrentOrder.Pizzas.FirstOrDefault().ToppingList) } // catch (Microsoft.EntityFrameworkCore.DbUpdateException) // { // Console.WriteLine("couldn't "); // } catch (System.Exception e) { Console.WriteLine("customer not found" + e.Message + "\n" + e.StackTrace); customer = null; return(false); } if (c == null) { Console.WriteLine("customer not found"); customer = null; return(false); } else if (Customer.Compare(c.Password, password)) { Console.WriteLine("login success"); customer = c; // if (c.CurrentOrder != null) // { // c.CurrentOrder.Pizzas.ForEach(pizza => pizza.PizzaSize = db.Sizes.Where(s => s.ComponentId == pizza.Property())); // db.Sizes.Where(s => ) // } return(true); } else { Console.WriteLine("passwords not matching"); customer = null; return(false); } } }