Esempio n. 1
0
        public void AddPizza(PizzaClass.PizzaSize size, HashSet <string> ingrediants)
        {
            if (pizzas.Count > 12)
            {
                throw new OrderTooLargeException();
            }
            PizzaClass pizza = new PizzaClass(size, ingrediants);

            pizzas.Add(pizza);
            UpdateTotal();
        }
        public int GetPizzaID(HashSet <string> Ingrediants, PizzaClass.PizzaSize size)
        {
            HashSet <Pizza> ListOfPizzas = _db.Pizza
                                           .Where(p => p.Size == (int)size) //size matters, for PizzaIds
                                           .Where(p => p.IngrediantsOnPizza.All(
                                                      iop => Ingrediants.Contains(
                                                          iop.Ingrediant.IngrediantName)
                                                      )) // pizzas where all the ingrediants are on the list
                                           .Where(p => Ingrediants.All(
                                                      i => p.IngrediantsOnPizza.Select(j => j.Ingrediant.IngrediantName).Contains(i)
                                                      )) // pizzas where all the ingrediants in the HashSet are on the Pizza
                                           .ToHashSet();

            if (ListOfPizzas.Count == 0)   // No such pizza? Make one, then return the id of the new pizza.
            {
                _db.Pizza.Add(Map(new PizzaClass(size, Ingrediants), GenerateIngrediantDictionary()));
                return(GetPizzaID(Ingrediants, size));
            }
            if (ListOfPizzas.Count > 1)
            {
                throw new DatabaseBadException(); // can't have more than one Pizza with the same set of toppings; something has gone wrong.
            }
            return(ListOfPizzas.First().PizzaId);
        }