Exemplo n.º 1
0
        // RemoveSingleItem - Remove one quantity of toRemove from this order.
        public void RemoveSingleItem(MenuItem toRemove)
        {
            // If there are no items, then do nothing.
            if (OrderContents == null)
            {
                return;
            }

            // Create a list of all current item IDs.
            string[] itemIDs = OrderContents.Split(',');

            // Convert this item's ID into a string
            // and see whether it is in the ID list.
            string removeID = toRemove.ItemID.ToString();

            if (itemIDs.Contains(removeID))
            {
                // If this is the only item, set the list to null.
                if (itemIDs.Length == 1)
                {
                    OrderContents = null;
                }
                else
                {
                    // If this is the first ID, remove it
                    // and its trailing comma.
                    if (itemIDs[0] == removeID)
                    {
                        OrderContents =
                            OrderContents.Substring(removeID.Length + 1);
                    }
                    else
                    {
                        // Otherwise, remove it and the leading comma.
                        int startIdx = OrderContents.IndexOf(removeID);
                        OrderContents =
                            OrderContents.Substring(0, startIdx - 1)
                            + OrderContents.Substring(startIdx +
                                                      removeID.Length);
                    }
                }

                // Update the price if possible.
                if (toRemove.Price != null)
                {
                    RawCost -= (int)toRemove.Price;
                }
            }
        }
Exemplo n.º 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);
        }