Exemplo n.º 1
0
        public void Create(OrderModel o)
        {
            // Order
            Order newOrder = new Order();

            newOrder.UserId  = _sa.GetUser(o.User.Email, o.User.Password).UserId;
            newOrder.StoreId = _sa.GetStore(o.StoreName).StoreId;
            // newOrder.StoreName = o.StoreName;
            newOrder.TotalCost = 0M;
            newOrder.OrderDate = DateTime.Now;
            // OrderPizza
            // Pizza
            foreach (var p in o.Pizzas)
            {
                Pizza newPizza = new Pizza();
                newPizza.Cost    = p.Cost;
                newPizza.SizeId  = _sa.GetSize(p.Size).SizeId;
                newPizza.CrustId = _sa.GetCrust(p.Crust).CrustId;
                newPizza.Cost    = _sa.GetSize(p.Size).Price + _sa.GetCrust(p.Crust).Price;
                foreach (var t in p.Toppings)
                {
                    PizzaTopping pt = new PizzaTopping();
                    pt.Pizza     = newPizza;
                    pt.ToppingId = _sa.GetTopping(t).ToppingId;
                    newPizza.PizzaTopping.Add(pt);
                    newPizza.Cost += _sa.GetTopping(t).Price;
                }
                OrderPizza op = new OrderPizza();
                op.Order = newOrder;
                op.Pizza = newPizza;
                newOrder.OrderPizza.Add(op);
                newOrder.TotalCost += newPizza.Cost;
            }
            _sa.CreateOrder(newOrder);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Address sampleAddress = new Address();

            sampleAddress.Address1 = "123 Abram";
            _sql.CreateAddress(sampleAddress);
            User sampleUser = new User();

            sampleUser.Username = "******";
            sampleUser.Address  = sampleAddress;
            _sql.CreateUser(sampleUser);
            Console.WriteLine(sampleUser.Username);
            User user = _sql.FindUser(Console.ReadLine());

            Console.WriteLine(user.Username);
            User herman = _sql.FindUser("Herman");

            Crust thinCrust = _sql.FindCrust(1);
            Size  smallSize = _sql.FindSize(1);

            Pizza samplePizza = new Pizza();

            samplePizza.Crust = thinCrust;
            samplePizza.Size  = smallSize;
            samplePizza.Price = 11.00M;

            OrderPizza p = new OrderPizza();

            p.Pizza = samplePizza;

            Store littleItaly = _sql.FindStore(1);
            Order sampleOrder = new Order();

            sampleOrder.Customer  = sampleUser;
            sampleOrder.Store     = littleItaly;
            sampleOrder.TotalCost = 189.00M;
            DateTime current = DateTime.Now;

            sampleOrder.OrderDate = current;
            sampleOrder.OrderPizza.Add(p);
            _sql.CreateOrder(sampleOrder);

            List <Order> usersOrder = _sql.FindUsersOrders(herman);



            foreach (Order o in usersOrder)
            {
                Console.WriteLine(o.Customer.Username);
                Console.WriteLine(o.OrderDate.Date);
                Console.WriteLine(o.TotalCost.Value);
                List <Pizza> OrdersPizza = _sql.FindOrdersPizzas(o);
                foreach (Pizza p in OrdersPizza)
                {
                    Console.WriteLine(p.Price);
                    Console.WriteLine(p.Crust);
                    Console.WriteLine(p.Size);
                }
            }
        }