예제 #1
0
        public bool DeleteOrder(PizzaOrder o)
        {
            var          po    = db.PizzaOrders.Where(x => x.PizzaOrderID == o.PizzaOrderID).FirstOrDefault();
            List <Order> order = db.Orders.Where(x => x.PizzaOrderID == o.PizzaOrderID).ToList();
            Pizza        pizza = new Pizza();

            foreach (var item in order)
            {
                pizza = db.Pizzas.Where(x => x.PizzaID == item.PizzaID).FirstOrDefault();
                db.Pizzas.Remove(pizza);
            }
            db.PizzaOrders.Remove(po);
            return(db.SaveChanges() > 0);
        }
예제 #2
0
        public bool InsertPizzaOrder(Customer customer, List <Pizza> pizza, List <List <Topping> > topping, List <List <Cheese> > cheeses, Email email, Name name, PhoneNumber number, CustomerAddress address)
        {
            PizzaOrder  pizzaorder = new PizzaOrder();
            PhoneNumber result     = db.PhoneNumbers.Where(x => x.PhoneNumber1 == number.PhoneNumber1).FirstOrDefault();

            if (result != null)
            {
                pizzaorder.CustomerID = (db.Customers.Where(x => x.PhoneNumber.PhoneNumber1 == number.PhoneNumber1).FirstOrDefault()).CustomerID;
            }
            else
            {
                pizzaorder.CustomerID = InsertCustomer(customer, name, email, number, address);
            }
            db.PizzaOrders.Add(pizzaorder);
            db.SaveChanges();
            db.Entry(pizzaorder).GetDatabaseValues();
            int pizzaOrderID = pizzaorder.PizzaOrderID;

            for (int i = 0; i < pizza.Count; i++)
            {
                InsertOrder(pizzaOrderID, pizza[i], topping[i], cheeses[i]);
            }
            return(true);
        }