コード例 #1
0
        public void Run(RestaurantContext db)
        {
            Console.WriteLine(this.description);
            Console.WriteLine("-------------------------------------\n");

            Restaurant restaurant = new Restaurant();

            Console.WriteLine("Restaurant address: ");
            string input = Console.ReadLine();

            if (db.Restaurants.Find(input) != null)
            {
                Console.WriteLine("A restaurant already exists with that address... Going back to menu");
                return;
            }

            restaurant.Address = input;

            Console.WriteLine("Restaurant name: ");
            restaurant.Name = Console.ReadLine();

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

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

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

            db.Add(restaurant);
            db.SaveChanges();

            foreach (string type in types)
            {
                RestaurantType restaurantType = db.RestaurantTypes.Find(type);
                if (restaurantType == null)
                {
                    restaurantType = new RestaurantType()
                    {
                        Type = type
                    };
                    db.RestaurantTypes.Add(restaurantType);
                    db.SaveChanges();
                }

                RestaurantRestaurantType restaurantRestaurantType = new RestaurantRestaurantType {
                    RestaurantAddress = restaurant.Address, TypeId = restaurantType.Type
                };

                db.Add(restaurantRestaurantType);
            }

            db.SaveChanges();
        }
コード例 #2
0
        public static Guest AddGuestToTable(RestaurantContext db, string name, Table table, DateTime time, List <Dish> dishes)
        {
            var guest = new Guest();

            if (db.Persons.Find(name) == null)
            {
                db.Add(new Person {
                    Name = name
                });
                db.SaveChanges();
            }

            guest.Name    = name;
            guest.TableId = table.TableId;
            guest.Time    = time;

            db.Add(guest);
            db.SaveChanges();

            foreach (var dish in dishes)
            {
                db.Add(new GuestDish {
                    DishId = dish.DishId, GuestId = guest.GuestId
                });
                db.SaveChanges();
            }

            return(guest);
        }
コード例 #3
0
        public static Waiter AddWaiterToRestaurant(RestaurantContext db, string name, int salary, Restaurant restaurant, List <Table> tables)
        {
            Waiter waiter = db.Waiters.Find(name);

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

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

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

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

            foreach (var table in tables)
            {
                db.Add(new TableWaiter {
                    TableId = table.TableId, Name = waiter.Name
                });
                db.SaveChanges();
            }

            return(waiter);
        }
コード例 #4
0
        public static Restaurant AddRestaurant(RestaurantContext db, string address, string name, List <string> types)
        {
            Restaurant restaurant = db.Restaurants.Find(address);

            if (restaurant != null)
            {
                return(null);
            }

            restaurant         = new Restaurant();
            restaurant.Address = address;
            restaurant.Name    = name;

            db.Add(restaurant);
            db.SaveChanges();

            foreach (var type in types)
            {
                RestaurantType restaurantType = db.RestaurantTypes.Find(type);
                if (restaurantType == null)
                {
                    restaurantType = new RestaurantType()
                    {
                        Type = type
                    };
                    db.RestaurantTypes.Add(restaurantType);
                    db.SaveChanges();
                }

                RestaurantRestaurantType restaurantRestaurantType = new RestaurantRestaurantType {
                    RestaurantAddress = restaurant.Address, TypeId = restaurantType.Type
                };

                db.Add(restaurantRestaurantType);
            }

            db.SaveChanges();

            return(restaurant);
        }
コード例 #5
0
        public static Review AddReviewFromGuest(RestaurantContext db, Guest guest, string text, int stars)
        {
            Review review = new Review();

            review.RestaurantAddress = guest.Table.RestaurantAddress;
            review.Guests.Add(guest);
            review.Text  = text;
            review.Stars = stars;

            db.Add(review);
            db.SaveChanges();

            foreach (var guestDish in db.GuestDishes.Where(gd => gd.GuestId == guest.GuestId).ToList())
            {
                db.Add(new DishReview {
                    DishId = guestDish.DishId, ReviewId = review.ReviewId
                });
                db.SaveChanges();
            }

            return(review);
        }
コード例 #6
0
        public static Dish AddDishToRestaurant(RestaurantContext db, string name, int price, List <string> types, Restaurant restaurant)
        {
            var dish = new Dish();

            dish.RestaurantAddress = restaurant.Address;
            dish.Name  = name;
            dish.Price = price;

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

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

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

                db.Add(restaurantRestaurantType);
                db.SaveChanges();
            }

            db.SaveChanges();

            return(dish);
        }
コード例 #7
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();
        }
コード例 #8
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();
                    }
                }
            }
        }
コード例 #9
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();
        }