public PizzaParty GetPizzaParty(int id)
        {
            PizzaParty pizzaPartyToReturn = null;

            foreach (var pizzaParty in _pizzaParties)
            {
                if (pizzaParty.Id == id)
                {
                    pizzaPartyToReturn = pizzaParty;

                    break;
                }
            }

            return(pizzaPartyToReturn);
        }
Ejemplo n.º 2
0
    public static void Main()
    {
        PizzaParty calculator = new PizzaParty();

        Console.WriteLine("How many people?");
        string peopleEntry = Console.ReadLine();
        int    people;

        while (!int.TryParse(peopleEntry, out people) || people <= 0)
        {
            Console.WriteLine("Must be greater than 0. Enter number of people: ");
            peopleEntry = Console.ReadLine();
        }

        Console.WriteLine("How many pizzas do you have?");
        string pizzaEntry = Console.ReadLine();
        int    pizzas;

        while (!int.TryParse(pizzaEntry, out pizzas) || pizzas < 0)
        {
            Console.WriteLine("Must be greater than 0. Enter number of pizzas: ");
            pizzaEntry = Console.ReadLine();
        }

        Console.WriteLine("How many slices per pizza?");
        string pizzaSlicesEntry = Console.ReadLine();
        int    pizzaSlices;

        while (!int.TryParse(pizzaSlicesEntry, out pizzaSlices) || pizzaSlices * pizzas < people)
        {
            Console.WriteLine("Not enough slices. Enter number of slices per pizza: ");
            pizzaSlicesEntry = Console.ReadLine();
        }

        Console.WriteLine(people + " people with " + pizzas + " pizzas.");
        int slicesPerPerson = (pizzas * pizzaSlices) / people;

        Console.WriteLine("Each person gets " + slicesPerPerson + " piece" + ((slicesPerPerson > 1) ? "s" : "") + " of pizza.");
        Console.WriteLine("There are " + (pizzas * pizzaSlices - people * slicesPerPerson) + " leftover pieces.");
    }
Ejemplo n.º 3
0
        protected override void Seed(Context context)
        {
            var pizza1 = new Pizza()
            {
                Name = "Wakin' Bacon"
            };
            var pizza2 = new Pizza()
            {
                Name = "Italian Stallion"
            };

            var ingredient1 = new Ingredient()
            {
                Name = "Sausage"
            };

            var ingredient2 = new Ingredient()
            {
                Name = "Cheese"
            };

            var ingredient3 = new Ingredient()
            {
                Name = "Sausage Gravy"
            };

            var role1 = new Role()
            {
                Name = "Meat"
            };
            var role2 = new Role()
            {
                Name = "Other"
            };

            var pizzaParty1 = new PizzaParty()
            {
                Pizza       = pizza1,
                PizzaCost   = 12,
                PublishedOn = DateTime.Today
            };

            pizzaParty1.AddIngredient(ingredient1, role1);
            pizzaParty1.AddIngredient(ingredient2, role2);

            var pizzaParty2 = new PizzaParty()
            {
                Pizza       = pizza2,
                PizzaCost   = 14,
                PublishedOn = DateTime.Today
            };

            pizzaParty2.AddIngredient(ingredient2, role1);
            pizzaParty2.AddIngredient(ingredient3, role2);

            var pizzaParty3 = new PizzaParty()
            {
                Pizza       = pizza2,
                PizzaCost   = 124,
                PublishedOn = DateTime.Today
            };

            pizzaParty3.AddIngredient(ingredient1, role1);
            pizzaParty3.AddIngredient(ingredient3, role2);

            context.PizzaParties.Add(pizzaParty1);
            context.PizzaParties.Add(pizzaParty2);
            context.PizzaParties.Add(pizzaParty3);

            context.SaveChanges();
        }