Example #1
0
        // AddNewOrder - Create a new order and add it to Orders.
        public void AddNewOrder()
        {
            // Create the order.
            var db       = new PickUpOrderDBEntities2();
            var newOrder = new Order();

            db.Orders.Add(newOrder);
            db.SaveChanges();

            // If the order string is null, use this ID to start.
            if (Orders == null)
            {
                Orders = newOrder.OrderID.ToString();
            }
            else
            {
                Orders += "," + newOrder.OrderID;
            }
        }
Example #2
0
        // ContentsToItemList - Return a list of the items referenced by
        //                      the orderContents string.
        public List <MenuItem> ContentsToItemList()
        {
            if (OrderContents == null)
            {
                return(null);
            }

            // Establish a database connection.
            var db = new PickUpOrderDBEntities2();

            // Create the list to be returned.
            var itemObjects = new List <MenuItem>();

            // Split the ID string. For each ID value,
            // get the corresponding item and add it to itemObjects.
            string[] itemIDs = OrderContents.Split(',');
            foreach (string item in itemIDs)
            {
                int id = int.Parse(item);
                itemObjects.Add(db.MenuItems.Find(id));
            }
            return(itemObjects);
        }
Example #3
0
        // OrdersToList - Return a list of the orders referenced by
        //                the order string.
        public List <Order> OrdersToList()
        {
            if (Orders == null)
            {
                return(null);
            }

            // Establish a database connection.
            var db = new PickUpOrderDBEntities2();

            // Create the list to be returned.
            var orderObjects = new List <Order>();

            // Split the ID string. For each ID value,
            // get the corresponding order and add it to orderObjects.
            string[] orderIDs = Orders.Split(',');
            foreach (string order in orderIDs)
            {
                int id = int.Parse(order);
                orderObjects.Add(db.Orders.Find(id));
            }
            return(orderObjects);
        }
Example #4
0
        // GetCategoryDropdown - Build a dropdown list of all categories.
        public static List <SelectListItem> GetCategoryDropdown()
        {
            var db   = new PickUpOrderDBEntities2();
            var cats = new List <SelectListItem>();

            // If there are no categories, add the four defaults.
            if (db.Categories.Count() == 0)
            {
                db.Categories.Add(new Category
                {
                    CategoryName = "Main Dishes"
                });
                db.Categories.Add(new Category
                {
                    CategoryName = "Appetizers"
                });
                db.Categories.Add(new Category
                {
                    CategoryName = "Desserts"
                });
                db.Categories.Add(new Category
                {
                    CategoryName = "Drinks"
                });
                db.SaveChanges();
            }

            foreach (Category c in db.Categories)
            {
                cats.Add(new SelectListItem
                {
                    Text  = c.CategoryName,
                    Value = c.CategoryID.ToString()
                });
            }
            return(cats);
        }