Пример #1
0
        public void Run(RestaurantContext db)
        {
            Console.WriteLine(this.description);
            Console.WriteLine("-------------------------------------\n");

            Table table = new Table();

            List <Restaurant> restaurantsToPrint = db.Restaurants.ToList();

            Console.WriteLine("Listing all available restaurants:");
            foreach (var r in restaurantsToPrint)
            {
                Console.WriteLine("Name: {0}, \tAddress: {1}", r.Name, r.Address);
            }

            Console.WriteLine("Enter address of restaurant to add dish to:");
            string input = Console.ReadLine();

            Restaurant restaurant = db.Restaurants.Find(input);

            if (restaurant == null)
            {
                Console.WriteLine("Restaurant does not exist, returning to menu...");
                return;
            }

            table.RestaurantAddress = restaurant.Address;



            List <Table> currentTables = db.Tables.Where(t => t.RestaurantAddress == table.RestaurantAddress).ToList();

            if (currentTables.Any())
            {
                Console.WriteLine("This restaurant currently has the following tables:");
                foreach (var t in currentTables)
                {
                    Console.WriteLine("Table " + t.Number);
                }
            }
            else
            {
                Console.WriteLine("This restaurant currently has no tables...");
            }

            Console.WriteLine("Enter new table number (must be a whole number):");
            input = Console.ReadLine();
            int tableNumber = 0;

            while (!int.TryParse(input, out tableNumber))
            {
                Console.WriteLine("You failed to enter a WHOLE number, try again...");
                input = Console.ReadLine();
            }

            table.Number = tableNumber;

            if (db.Tables.Where(t => t.RestaurantAddress == table.RestaurantAddress && t.Number == table.Number).ToList().Any())
            {
                Console.WriteLine("That table already exists at this restaurant, exiting to menu...");
                return;
            }

            db.Add(table);
            db.SaveChanges();
        }
Пример #2
0
        public void Run(RestaurantContext db)
        {
            Console.WriteLine(this.description);
            Console.WriteLine("-------------------------------------\n");

            Console.WriteLine("Enter name of new waiter:");
            string name = Console.ReadLine();

            Waiter waiter = db.Waiters.Find(name);

            if (waiter != null)
            {
                Console.WriteLine("This person is already a waiter, exiting to menu...");
                return;
            }

            Person person = db.Persons.Find(name);

            if (person != null)
            {
                db.Persons.Remove(person);
            }

            waiter      = new Waiter();
            waiter.Name = name;

            Console.WriteLine("Enter salary for {0} - Must be a whole number:", waiter.Name);

            string input  = Console.ReadLine();
            int    salary = 0;

            while (!int.TryParse(input, out salary))
            {
                Console.WriteLine("You failed to enter a WHOLE number, try again...");
                input = Console.ReadLine();
            }

            waiter.Salary = salary;

            db.Add(waiter);
            db.SaveChanges();

            foreach (var restaurant in db.Restaurants.ToList())
            {
                Console.WriteLine($"Tables at {restaurant.Name}, {restaurant.Address}");
                foreach (var table in db.Tables.Where(t => t.RestaurantAddress == restaurant.Address).OrderBy(t => t.Number).ToList())
                {
                    Console.WriteLine($"Table {table.Number} with id: {table.TableId}");
                }
            }

            while (input != "x")
            {
                Console.WriteLine($"Enter tableIds to assign {waiter.Name} to - Seperate with enter, enter \"x\" to finish");
                input = Console.ReadLine();
                int tableToFind = 0;

                if (int.TryParse(input, out tableToFind))
                {
                    Table table = db.Tables.Find(tableToFind);

                    if (table == null)
                    {
                        Console.WriteLine("Table doesn't exist");
                    }
                    else
                    {
                        db.Add(new TableWaiter {
                            TableId = table.TableId, Name = waiter.Name
                        });
                        db.SaveChanges();
                    }
                }
            }
        }
        public void Run(RestaurantContext db)
        {
            Console.WriteLine(this.description);
            Console.WriteLine("-------------------------------------\n");

            List <Restaurant> restaurants = db.Restaurants.ToList();

            if (!restaurants.Any())
            {
                Console.WriteLine("No restaurants");
                return;
            }

            Console.WriteLine("Listing all restaurants:");

            foreach (var toPrint in restaurants)
            {
                Console.WriteLine($"{toPrint.Name} - {toPrint.Address}: {toPrint.Reviews.Count} reviews available.");
            }

            Console.WriteLine("\nEnter address of restaurant to view:");
            string     input      = Console.ReadLine();
            Restaurant restaurant = db.Restaurants.Find(input);

            if (restaurant == null)
            {
                Console.WriteLine("The address you typed did not match any existing restaurants...");
                return;
            }


            foreach (var table in db.Tables.Where(t => t.RestaurantAddress == restaurant.Address).OrderBy(t => t.Number))
            {
                List <Review> reviews = new List <Review>();

                foreach (var guest in table.Guests)
                {
                    if (!reviews.Contains(guest.Review))
                    {
                        reviews.Add(guest.Review);
                    }
                }

                Console.WriteLine();
                Console.WriteLine($"Guests at table {table.Number} have said:");
                foreach (var review in reviews)
                {
                    if (review.Guests.Any())
                    {
                        Console.Write("Names ");
                        foreach (var reviewguest in review.Guests)
                        {
                            Console.Write($"- {reviewguest.Name}");
                        }

                        Console.WriteLine();
                        Console.WriteLine($"\"{review.Text}\"\n{review.Stars} out of 5 stars.");
                        Console.WriteLine("They ate:");
                        Console.WriteLine("----------------------------------------");
                        foreach (var dishReview in db.DishReviews.Where(r => r.ReviewId == review.ReviewId))
                        {
                            Console.WriteLine(dishReview.Dish.Name);
                        }
                        Console.WriteLine("----------------------------------------");
                    }
                    else
                    {
                        Console.WriteLine("No reviews for this table.");
                    }
                }
            }
        }
Пример #4
0
        public void Run(RestaurantContext db)
        {
            Console.WriteLine(this.description);
            Console.WriteLine("-------------------------------------\n");

            Dish dish = new Dish();

            List <Restaurant> restaurantsToPrint = db.Restaurants.ToList();

            Console.WriteLine("Listing all available restaurants:");
            foreach (var r in restaurantsToPrint)
            {
                Console.WriteLine("Name: {0}, \tAddress: {1}", r.Name, r.Address);
            }

            Console.WriteLine("Enter address of restaurant to add dish to:");
            string input = Console.ReadLine();

            Restaurant restaurant = db.Restaurants.Find(input);

            if (restaurant == null)
            {
                Console.WriteLine("Restaurant does not exist, returning to menu...");
                return;
            }

            dish.RestaurantAddress = restaurant.Address;

            Console.WriteLine("Enter name of dish:");
            dish.Name = Console.ReadLine();

            Console.WriteLine("Enter price of dish (must be an whole number):");
            input = Console.ReadLine();
            int price = 0;

            while (!int.TryParse(input, out price))
            {
                Console.WriteLine("You failed to enter a WHOLE number, try again...");
                input = Console.ReadLine();
            }

            dish.Price = price;

            db.Add(dish);
            db.SaveChanges();

            input = "0";
            List <string> types = new List <string>();

            while (input != "x")
            {
                Console.WriteLine("Add dish types - Seperate with enter, enter \"x\" to finish: ");
                input = Console.ReadLine();

                if (input != "x" && !types.Contains(input))
                {
                    types.Add(input);
                }
            }

            foreach (string type in types)
            {
                DishType dishType = db.DishTypes.Find(type);
                if (dishType == null)
                {
                    dishType = new DishType()
                    {
                        Type = type
                    };
                    db.DishTypes.Add(dishType);
                    db.SaveChanges();
                }

                DishDishType dishDishType = new DishDishType()
                {
                    DishId = dish.DishId, TypeId = dishType.Type
                };

                db.Add(dishDishType);
            }

            db.SaveChanges();
        }
        public static void Populate(RestaurantContext db)
        {
            var jerrys = AddRestaurant(db, "Jordbrovej 11, 8200 Aarhus N", "Jerry's Pizza", new List <string>()
            {
                "Fast Food", "Pizzaria"
            });
            var mcdonalds = AddRestaurant(db, "Randersvej 150, 8200 Aarhus N", "McDonalds", new List <string>()
            {
                "Fast Food", "Burger Place"
            });
            var mash = AddRestaurant(db, "Banegaardspladsen 12, 8000 Aarhus", "MASH", new List <string>()
            {
                "Gourmet", "Meat"
            });
            var noma = AddRestaurant(db, "Refshalevej 96, 1432 Koebenhavn K", "Noma", new List <string>()
            {
                "Gourmet", "Pretentious"
            });

            var peppepizza = AddDishToRestaurant(db, "Pepperoni Pizza", 69, new List <string> {
                "Pizza"
            }, jerrys);
            var hampizza = AddDishToRestaurant(db, "Ham Pizza", 69, new List <string> {
                "Pizza"
            }, jerrys);
            var veggiepizza = AddDishToRestaurant(db, "Vegetarian Pizza", 59, new List <string> {
                "Pizza", "Vegetarian"
            }, jerrys);

            var cheeseburger = AddDishToRestaurant(db, "Cheeseburger", 10, new List <string> {
                "Burger"
            }, mcdonalds);
            var mcwhopper = AddDishToRestaurant(db, "McWhopper", 52, new List <string> {
                "Burger"
            }, mcdonalds);
            var veggieburger = AddDishToRestaurant(db, "McVeggie", 35, new List <string> {
                "Burger", "Vegetarian"
            }, mcdonalds);

            var bigsteak = AddDishToRestaurant(db, "Big juicy steak", 322, new List <string> {
                "Meat"
            }, mash);
            var smallsteak = AddDishToRestaurant(db, "Small dry steak", 267, new List <string> {
                "Meat"
            }, mash);
            var veggiesteak = AddDishToRestaurant(db, "Pretend steak", 125, new List <string> {
                "Vegetarian"
            }, mash);

            var antfood = AddDishToRestaurant(db, "Food for ants", 999, new List <string> {
                "Vegetarian", "Very small"
            }, noma);
            var meatbubble = AddDishToRestaurant(db, "A bubble made from meat", 1500, new List <string> {
                "Strange"
            }, noma);
            var spegepolse = AddDishToRestaurant(db, "Rugbrød med spegepolse", 500, new List <string> {
                "Vegetarian", "Dansk"
            }, noma);

            var jerrysTables    = AddTablesToRestaurant(db, jerrys, 3);
            var mcdonaldsTables = AddTablesToRestaurant(db, mcdonalds, 4);
            var mashTables      = AddTablesToRestaurant(db, mash, 5);
            var nomaTables      = AddTablesToRestaurant(db, noma, 3);

            var mashWaiter = AddWaiterToRestaurant(db, "Tjen Erling", 12000, mash, mashTables);
            var nomaWaiter = AddWaiterToRestaurant(db, "Norm Al", 12000, noma, nomaTables);

            var john = AddGuestToTable(db, "John", nomaTables[0], DateTime.Now, new List <Dish> {
                antfood
            });
            var alex = AddGuestToTable(db, "Alex", nomaTables[0], DateTime.Now, new List <Dish> {
                antfood
            });
            var peter = AddGuestToTable(db, "Peter", nomaTables[0], DateTime.Now, new List <Dish> {
                antfood, meatbubble
            });
            var elias = AddGuestToTable(db, "Elias", nomaTables[0], DateTime.Now, new List <Dish> {
                spegepolse, meatbubble
            });
            var magnus = AddGuestToTable(db, "Magnus", nomaTables[0], DateTime.Now, new List <Dish> {
                antfood, spegepolse
            });
            var loner = AddGuestToTable(db, "Lone R", nomaTables[1], DateTime.Now, new List <Dish> {
                antfood, spegepolse
            });

            var lonerReview =
                AddReviewFromGuest(db, loner, "I was all alone, it was great", 5);
            var magnusReview =
                AddReviewFromGuest(db, magnus, "I got ant food and a spegepolsemad, this was terrible.", 1);
            var eliasReview =
                AddReviewFromGuest(db, elias, "The meat bubble was amazing!", 5);
            var johnReview =
                AddReviewFromGuest(db, john, "I didn't really enjoy the antfood, but the meatbubble was great!", 4);
            var peterReview =
                AddReviewFromGuest(db, peter, "Since i'm an ant, the antfood was great", 5);
            var alexReview =
                AddReviewFromGuest(db, alex, "Don't let anyone know i'm an anteater, i just pretended to like the antfood so i could get closer to peter", 5);
        }