Beispiel #1
0
        public static Meals GetMealWithID(int MealID)
        {
            string str = DataAccess.CnnVal(DataAccess.currentDBname);

            using (IDbConnection connection = new SqlConnection(str))
            {
                var   toReturn = connection.QueryFirst <Meals>("SELECT * FROM dbo.Dishes WHERE id=@id", new { id = MealID });
                Meals meal     = Meals.GetMealClassWithDishType(toReturn.Dishtype, toReturn);


                if (meal.GetType() == typeof(Burger))
                {
                    dynamic burgerData = connection.QuerySingle("SELECT * FROM dbo.Dishes WHERE Id=@dishid", new { dishid = meal.Id });
                    (meal as Burger).Bun    = burgerData.Bun;
                    (meal as Burger).Cheese = burgerData.Cheese;
                    (meal as Burger).Patty  = burgerData.Patty;
                }

                if (meal.GetType() == typeof(Pizza))
                {
                    dynamic pizzaData = connection.QuerySingle("SELECT * FROM dbo.Dishes WHERE Id=@dishid", new { dishid = meal.Id });
                    (meal as Pizza).Toppings = pizzaData.Toppings;
                }

                if (meal.GetType() == typeof(Pasta))
                {
                    dynamic pastaData = connection.QuerySingle("SELECT * FROM dbo.Dishes WHERE Id=@dishid", new { dishid = meal.Id });
                    (meal as Pasta).Meat      = pastaData.Meat;
                    (meal as Pasta).Pastatype = pastaData.Pastatype;
                }

                if (meal.GetType() == typeof(Steak))
                {
                    dynamic steakData = connection.QuerySingle("SELECT * FROM dbo.Dishes WHERE Id=@dishid", new { dishid = meal.Id });
                    (meal as Steak).Steaktype = steakData.Steaktype;
                    (meal as Steak).Side      = steakData.Side;
                }

                if (meal.GetType() == typeof(Drinks))
                {
                    dynamic drinkData = connection.QuerySingle("SELECT * FROM dbo.Dishes WHERE Id=@dishid", new { dishid = meal.Id });
                    (meal as Drinks).Amount      = (int)drinkData.Amount;
                    (meal as Drinks).isAlcoholic = drinkData.isAlcoholic;
                }

                var allergens = connection.Query <Allergen.AllergenType>("SELECT AllergenId FROM AllergensInDishes WHERE DishId=@id", new { id = MealID }).ToArray();
                foreach (var allergenAsInt in allergens)
                {
                    meal.AddAllergen(allergenAsInt);
                }

                return(meal);
            }
        }
Beispiel #2
0
        public static int InsertMealToDB(Meals meal)
        {
            string str = DataAccess.CnnVal(DataAccess.currentDBname);
            int    mealId;

            using (IDbConnection connection = new SqlConnection(str))
            {
                mealId = connection.QuerySingle <int>("INSERT dbo.Dishes (Name, Description, Sauce, Price, Dishtype) OUTPUT INSERTED.ID " +
                                                      "VALUES (@name, @description, @sauce, @price, @dishtype)", new { name = meal.Name, description = meal.Description, sauce = meal.Sauce, price = meal.Price, dishtype = meal.Dishtype });

                if (meal.GetType() == typeof(Burger))
                {
                    mealId = connection.QuerySingle <int>("UPDATE dbo.Dishes SET Bun=@bun, Patty=@patty, Cheese=@cheese OUTPUT INSERTED.ID WHERE Id=@id", new { bun = (meal as Burger).Bun, patty = (meal as Burger).Patty, cheese = (meal as Burger).Cheese, id = mealId });
                }

                else if (meal.GetType() == typeof(Pizza))
                {
                    mealId = connection.QuerySingle <int>("UPDATE dbo.Dishes SET Toppings=@toppings OUTPUT INSERTED.ID WHERE Id=@id)", new { toppings = (meal as Pizza).Toppings, id = mealId });
                }

                else if (meal.GetType() == typeof(Pasta))
                {
                    mealId = connection.QuerySingle <int>("UPDATE dbo.Dishes SET Pastatype=@pastatype, Meat=@meat OUTPUT INSERTED.ID WHERE Id=@id", new { meat = (meal as Pasta).Meat, pastatype = (meal as Pasta).Pastatype, id = mealId });
                }

                else if (meal.GetType() == typeof(Steak))
                {
                    mealId = connection.QuerySingle <int>("UPDATE dbo.Dishes SET Steaktype=@steaktype, Side=@side  OUTPUT INSERTED.ID WHERE Id=@id", new { steaktype = (meal as Steak).Steaktype, side = (meal as Steak).Side, id = mealId });
                }

                else if (meal.GetType() == typeof(Drinks))
                {
                    mealId = connection.QuerySingle <int>("UPDATE dbo.Dishes SET Amount=@amount, isAlcoholic=@isalcoholic OUTPUT INSERTED.ID WHERE Id=@id", new { amount = (meal as Drinks).Amount, isalcoholic = (meal as Drinks).isAlcoholic, id = mealId });
                }
            }

            if (mealId > 0 && meal.GetAllergens().Count > 0)
            {
                using (IDbConnection connection = new SqlConnection(str))
                {
                    foreach (var allergen in meal.GetAllergens())
                    {
                        connection.Execute("INSERT dbo.AllergensInDishes (AllergenId, DishId) VALUES (@Allergenid, @Dishid)", new { Allergenid = (int)allergen, Dishid = mealId });
                    }
                }
            }
            return(mealId);
        }
Beispiel #3
0
        public Meals GetAllergenFromUSer(Meals meal)
        {
            Console.WriteLine("Is the food allergen free?");
            Console.WriteLine("Answer Y or N");
            var allergens = Enum.GetNames(typeof(Allergen.AllergenType));

            foreach (string str in allergens)
            {
                if (str != "negative")
                {
                    Console.WriteLine();
                    Console.WriteLine(str);
                    bool answer = GetYesOrNoFromUser();
                    if (answer == true)
                    {
                        Allergen.AllergenType an = (Allergen.AllergenType)Enum.Parse(typeof(Allergen.AllergenType), str);
                        meal.AddAllergen(an);
                    }
                }
            }
            return(meal);
        }
Beispiel #4
0
        public static Meals GetMealClassWithDishType(int type, Meals template = null)
        {
            Meals meal = null;

            if (type == 1 || type == 6)
            {
                meal = new Meals();
            }
            if (type == 2)
            {
                meal = new Burger();
            }
            if (type == 3)
            {
                meal = new Pizza();
            }
            if (type == 4)
            {
                meal = new Pasta();
            }
            if (type == 5)
            {
                meal = new Steak();
            }
            if (type == 7)
            {
                meal = new Drinks();
            }
            if (template != null)
            {
                meal.Name        = template.Name;
                meal.Description = template.Description;
                meal.Sauce       = template.Sauce;
                meal.Price       = template.Price;
                meal.Id          = template.Id;
            }
            return(meal);
        }
Beispiel #5
0
        public Meals CreateMeal()
        {
            string name = GetMealName();

            Console.WriteLine("Choose the type of the meal you want to create:");
            Console.WriteLine("1. Drink");
            Console.WriteLine("2. Burger");
            Console.WriteLine("3. Pizza");
            Console.WriteLine("4. Pasta");
            Console.WriteLine("5. Steak");
            Console.WriteLine("6. Starter");
            Console.WriteLine("7. Dessert");

            int   selected = int.Parse(Console.ReadLine());
            Meals meal     = null;

            if (selected == 1)
            {
                meal          = new Drinks();
                meal.Dishtype = 7;
            }

            if (selected == 2)
            {
                meal          = new Burger();
                meal.Dishtype = 2;
            }

            if (selected == 3)
            {
                meal          = new Pizza();
                meal.Dishtype = 3;
            }

            if (selected == 4)
            {
                meal          = new Pasta();
                meal.Dishtype = 4;
            }

            if (selected == 5)
            {
                meal          = new Steak();
                meal.Dishtype = 5;
            }

            if (selected == 6)
            {
                meal          = new Meals();
                meal.Dishtype = 1;
            }

            if (selected == 7)
            {
                meal          = new Meals();
                meal.Dishtype = 6;
            }

            if (meal.GetType() == typeof(Drinks))
            {
                Console.WriteLine("Is the drink alcoholic?");
                Console.WriteLine("Answer Y or N");
                bool alcoholic = GetYesOrNoFromUser();
                if (alcoholic != true)
                {
                    (meal as Drinks).isAlcoholic = true;
                }
                else
                {
                    (meal as Drinks).isAlcoholic = false;
                }

                Console.WriteLine("Give the drink amount in centilitres:");
                int amount = int.Parse(Console.ReadLine());
                (meal as Drinks).Amount = amount;
            }

            if (meal.GetType() == typeof(Burger))
            {
                Console.WriteLine("Give patty info:");
                (meal as Burger).Patty = StringChecker(Console.ReadLine());

                Console.WriteLine("Give cheese info:");
                (meal as Burger).Cheese = StringChecker(Console.ReadLine());

                Console.WriteLine("Give bun info:");
                (meal as Burger).Bun = StringChecker(Console.ReadLine());
            }

            if (meal.GetType() == typeof(Pizza))
            {
                Console.WriteLine("Give the pizza toppings:");
                (meal as Pizza).Toppings = StringChecker(Console.ReadLine());
            }

            if (meal.GetType() == typeof(Pasta))
            {
                Console.WriteLine("Give the pastatype:");
                (meal as Pasta).Pastatype = StringChecker(Console.ReadLine());

                Console.WriteLine("Give the meat:");
                (meal as Pasta).Meat = StringChecker(Console.ReadLine());

                (meal as Pasta).Sauce = GetSauce();
            }

            if (meal.GetType() == typeof(Steak))
            {
                Console.WriteLine("Give the type of the steak:");
                (meal as Steak).Steaktype = StringChecker(Console.ReadLine());

                Console.WriteLine("Give the side with the steak:");
                (meal as Steak).Side = StringChecker(Console.ReadLine());

                (meal as Steak).Sauce = GetSauce();
            }



            Console.WriteLine("Do you want to add a description to the dish?");
            Console.WriteLine("Answer Y or N");
            bool answer = GetYesOrNoFromUser();

            if (answer == true)
            {
                meal.Description = GetMealDescription();
            }


            GetAllergenFromUSer(meal);

            float price = GetPrice();

            meal.Name  = name;
            meal.Price = price;

            return(meal);
        }
Beispiel #6
0
        public void RemoveSelectedMealFromCategory(Category category)
        {
            Meals selectedMeal = SelectMealFromCategory(category);

            category.meals.Remove(selectedMeal);
        }
Beispiel #7
0
        public void ShowMealData(Meals meal)
        {
            Console.WriteLine();
            Console.WriteLine($"Id: {meal.Id}");
            Console.WriteLine($"{meal.Name}");
            if (meal.Description != null)
            {
                Console.WriteLine($"{meal.Description}");
            }
            Type type = meal.GetType();

            if (type == typeof(Burger))
            {
                Burger burger = (Burger)meal;
                Console.WriteLine($"Patty: {burger.Patty}");
                Console.WriteLine($"Cheese: {burger.Cheese}");
                Console.WriteLine($"Bun: {burger.Bun}");
            }

            if (type == typeof(Pizza))
            {
                Pizza pizza = (Pizza)meal;
                Console.WriteLine($"Toppings: {pizza.Toppings}");
            }

            if (type == typeof(Pasta))
            {
                Pasta pasta = (Pasta)meal;
                Console.WriteLine($"Type of pasta: {pasta.Pastatype}");
                Console.WriteLine($"Meat: {pasta.Meat}");
            }

            if (type == typeof(Steak))
            {
                Steak steak = (Steak)meal;
                Console.WriteLine($"Type: {steak.Steaktype}");
                Console.WriteLine($"Side: {steak.Side}");
            }

            if (type == typeof(Drinks))
            {
                Drinks drink = (Drinks)meal;
                Console.WriteLine($"Amout: {drink.Amount}cl");
                if (drink.isAlcoholic == true)
                {
                    Console.WriteLine("Alcoholic");
                }
                else
                {
                    Console.WriteLine("Non-Alcoholic");
                }
            }

            if (meal.Sauce != null)
            {
                Console.WriteLine($"Sauce: {meal.Sauce}");
            }

            foreach (var allergen in meal.Allergentypes)
            {
                if (allergen == Allergen.AllergenType.glutenFree)
                {
                    Console.WriteLine("This dish is gluten free, " + Allergen.allergenChars[allergen]);
                }

                else if (allergen == Allergen.AllergenType.lactoseFree)
                {
                    Console.WriteLine("This dish is lactose free, " + Allergen.allergenChars[allergen]);
                }

                else if (allergen == Allergen.AllergenType.milkFree)
                {
                    Console.WriteLine("This dish is milk free, " + Allergen.allergenChars[allergen]);
                }

                else if (allergen == Allergen.AllergenType.lowLactose)
                {
                    Console.WriteLine("This dish is low lactose, " + Allergen.allergenChars[allergen]);
                }
            }

            Console.WriteLine($"Price: {meal.Price}€");
        }
Beispiel #8
0
        public void SuperMainMenu()
        {
            bool showMenu = true;

            while (showMenu == true)
            {
                Console.Clear();
                Console.WriteLine("\n ----- Main menu -----");
                Console.WriteLine($"Restaurant selected: {SelectedRestaurant.RestaurantName}");
                Console.WriteLine("1. Show all dishes");
                Console.WriteLine("2. Show restaurant menu");
                Console.WriteLine("3. Create a new dish");
                Console.WriteLine("4. Create a new restaurant");
                Console.WriteLine("5. Create a new menu for a restaurant");
                Console.WriteLine("6. Create a new category for a menu");

                Console.WriteLine("9. Change selected restaurant");
                Console.WriteLine("0. Exit");
                ConsoleKey selected = Console.ReadKey(true).Key;
                switch (selected)
                {
                case ConsoleKey.D1:
                    Console.Clear();
                    ShowMealsFromAllMealsList();
                    Console.WriteLine("\nPress any key to continue");
                    Console.ReadKey(true);
                    break;

                case ConsoleKey.D2:
                    Console.Clear();
                    Restaurant     r  = SelectedRestaurant;
                    RestaurantMenu rm = SelectMenuFromRestaurant(r);
                    Category       C1 = null;
                    if (rm != null)
                    {
                        C1 = SelectCategoryFromMenu(rm);
                    }
                    if (C1 != null)
                    {
                        ShowCategory(C1);
                        Console.WriteLine("\nPress any key to continue");
                        Console.ReadKey(true);
                    }
                    break;

                case ConsoleKey.D3:
                    Console.Clear();
                    Console.WriteLine("Create your new dish:");
                    Meals meal = CreateMeal();
                    Console.Clear();
                    Console.WriteLine("The dish you created:");
                    this.ShowMealData(meal);

                    Console.WriteLine("Do you want to add this dish to database?");
                    Console.WriteLine("Answer Y or N");
                    bool happyness = GetYesOrNoFromUser();
                    if (happyness == true)
                    {
                        int mealId = DataManager.InsertMealToDB(meal);
                        Console.WriteLine($"Dish added to the database with the Id: {mealId}");
                    }
                    Console.WriteLine("Dish creation complete.");
                    Console.WriteLine("\nPress any key to continue");
                    Console.ReadKey(true);
                    break;

                case ConsoleKey.D4:
                    Console.Clear();
                    Console.WriteLine("Create the new restaurant");
                    Restaurant restaurant = this.CreateNewRestaurant();
                    Console.Clear();
                    Console.WriteLine("The restaurant you created:");
                    this.ShowRestaurantInfo(restaurant);

                    Console.WriteLine("Do you want to add this restaurant to all restaurants list?");
                    Console.WriteLine("Answer Y or N");
                    bool acception = GetYesOrNoFromUser();
                    if (acception == true)
                    {
                        dataManager.AddRestaurantToAllRestaurantsList(restaurant);
                        Console.WriteLine("Restaurant is now added to the list.");
                    }
                    Console.WriteLine("Restaurant is now created.");
                    Console.WriteLine("\nPress any key to continue");
                    Console.ReadKey(true);
                    break;

                case ConsoleKey.D5:
                    Console.Clear();
                    Restaurant     r2             = SelectedRestaurant;
                    RestaurantMenu restaurantMenu = CreateNewMenu();
                    r2.restaurants.Add(restaurantMenu);
                    Console.WriteLine($"Current menus in {r2.RestaurantName}:");
                    ShowRestaurantWithMenuNumbers(r2);

                    Console.WriteLine("\nPress any key to continue");
                    Console.ReadKey(true);
                    break;

                case ConsoleKey.D6:
                    Console.Clear();
                    Category category = CreateCategory();
                    Console.WriteLine($"You created: {category.categoryName}");
                    Console.WriteLine("Do you want to add it to an existing menu?");
                    Console.WriteLine("Answer Y or N");
                    bool hopeThisWorks = GetYesOrNoFromUser();
                    if (hopeThisWorks == true)
                    {
                        Console.WriteLine("Choose the restaurant.");
                        Restaurant     r4  = SelectRestaurantFromAllRestaurantsList();
                        RestaurantMenu rm5 = SelectMenuFromRestaurant(r4);
                        rm5.menus.Add(category);
                        ShowMenuWithCategoryNumbers(rm5);
                    }
                    Console.WriteLine("\nPress any key to continue");
                    Console.ReadKey(true);
                    break;

                case ConsoleKey.D9:
                    SelectedRestaurant = this.SelectRestaurantFromAllRestaurantsList();
                    break;

                case ConsoleKey.D0:
                    showMenu = false;
                    break;
                }
            }
        }
Beispiel #9
0
 public void AddMealToAllMealsList(Meals meal)
 {
     _allMealsList.Add(meal);
 }