Esempio n. 1
0
        public List <domain.Order> ReadOrders(int id, string type = "Store")
        {
            List <domain.Order> orders = new List <domain.Order>();

            List <Order> orderEntities;

            if (type == "Store")
            {
                orderEntities = _db.Order.Where(o => o.StoreId == id).ToList();
            }
            else
            {
                orderEntities = _db.Order.Where(o => o.UserId == id).ToList();
            }

            foreach (Order o in orderEntities)
            {
                domain.Order newO = new domain.Order();
                newO.Date    = o.DateCreated;
                newO.Status  = o.Status;
                newO.OrderId = o.OrderId;
                newO.StoreId = o.StoreId;
                newO.UserId  = o.UserId;

                newO.Pizzas = ReadAllPizzas(newO.OrderId);
                orders.Add(newO);
            }
            return(orders);
        }
Esempio n. 2
0
 private static void FetchAllOrderIDForUserHistory()
 {
     try{
         var usersOrdersHistoryList = _db.Orders.Where(o => o.UserId == _CurrentUsersList[0].UserID).ToList();
         _CurrentUsersList[0].PizzaBoxStore.OrderHistory = new List <PizzaBox.Domain.Models.Order>();
         foreach (var ordersObjectDB in usersOrdersHistoryList)
         {
             var newOrderType = new PizzaBox.Domain.Models.Order();
             newOrderType.SetOrderID(ordersObjectDB.OrderId);
             _CurrentUsersList[0].PizzaBoxStore.OrderHistory.Add(newOrderType);
         }
     } catch {
         System.Console.WriteLine("Unable to reterive any orders from ");
     }
 }
Esempio n. 3
0
        public int CreateOrder(domain.Order order, int userid, int storeid)
        {
            var newOrder = new Order();

            newOrder.UserId      = userid;
            newOrder.StoreId     = storeid;
            newOrder.Status      = order.Status;
            newOrder.DateCreated = order.Date;
            _db.Order.Add(newOrder);
            _db.SaveChanges();
            int newOrderId = newOrder.OrderId;

            foreach (domain.Pizza p in order.Pizzas)
            {
                CreatePizza(p, newOrderId);
            }
            return(newOrderId);
        }
        public void CreateOrder(domain.Order order, int userId, int storeId)
        {
            var dbOrder = new Order();

            dbOrder.UserId      = (userId + 1);
            dbOrder.StoreId     = (storeId + 1);
            dbOrder.Done        = order.done;
            dbOrder.DateOrdered = System.DateTime.Now;
            //dbOrder.OrderId = dbOrder.OrderId + 1;

            _db.Order.Add(dbOrder);
            _db.SaveChanges();
            System.Console.WriteLine("FRUSTRATION:Order ID added");
            System.Console.WriteLine(ReadAllOrdersIds().Last());
            foreach (var p in order.Pizzas)
            {
                CreatePizza(p, ReadAllOrdersIds().Last());
            }
            _db.SaveChanges();
        }
        public void AddOrderToDB(domain.Order order)
        {
            int newOrderNumber = db.PizzaOrder.Max(p => p.OrderId) + 1;
            List <domain.Order> ordersToAdd = new List <domain.Order>();

            foreach (domain.Pizza pizza in order.pizzas)
            {
                int        store_ID = order.store.id;
                int        user_ID  = order.user;
                PizzaOrder dbOrder  = new PizzaOrder {
                    OrderId     = newOrderNumber,
                    StoreId     = store_ID,
                    PizzaId     = pizza.id,
                    UserId      = user_ID,
                    WhenOrdered = (DateTime)order.created,
                    TotalCost   = (float)order.totalCost,
                    Size        = pizza.size.ToString()
                };
                AddOrder(dbOrder);
                db.PizzaOrder.Add(dbOrder);
            }
            db.SaveChanges();
        }
        private void AddOrder(PizzaOrder order)
        {
            int storeID = (int)order.StoreId;
            int userID  = (int)order.UserId;
            int orderID = (int)order.OrderId;
            int pizzaID = (int)order.PizzaId;

            try {
                _ = orders[storeID];
            } catch (KeyNotFoundException) {
                orders.Add(storeID, new Dictionary <int, Dictionary <int, domain.Order> >());
                // Console.WriteLine("S" + storeID); // working
            }
            try {
                _ = orders[storeID][userID];
            } catch (KeyNotFoundException) {
                orders[storeID].Add(userID, new Dictionary <int, domain.Order>());
                // Console.WriteLine($"S{storeID} U{userID}");  // working
            }
            domain.Order domainOrder;
            try {
                domainOrder = orders[storeID][userID][orderID];
            } catch (KeyNotFoundException) {
                domainOrder = new domain.Order {
                    created = order.WhenOrdered,
                    store   = stores[storeID],
                    user    = order.UserId
                };
                orders[storeID][userID].Add(orderID, domainOrder);
                // Console.WriteLine($"S{storeID} U{userID} O{orderID}"); // working
            }
            domain.Pizza pizza = pizzas[pizzaID];
            pizza.size = order.Size[0];
            domainOrder.AddPizza(pizzas[pizzaID], true);
            orders[storeID][userID][orderID] = domainOrder;
        }
Esempio n. 7
0
 public void AddOrder(Order o)
 {
     this.CompletedOrders.Add(o);
 }