From 9aecbbd1b1f9c971f048420654d775c4889a2dd1 Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Wed, 4 Dec 2024 19:05:51 +0100 Subject: [PATCH] =?UTF-8?q?Litt=20mer=20p=C3=A5=20Codealong?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Codealong/CodeAlong0412/CodeAlong0412/App.cs | 89 ++++++++++++++----- .../CodeAlong0412/CodeAlong0412/recepies.cs | 26 ++++-- 2 files changed, 87 insertions(+), 28 deletions(-) diff --git a/Codealong/CodeAlong0412/CodeAlong0412/App.cs b/Codealong/CodeAlong0412/CodeAlong0412/App.cs index ea80cb2..83004a3 100644 --- a/Codealong/CodeAlong0412/CodeAlong0412/App.cs +++ b/Codealong/CodeAlong0412/CodeAlong0412/App.cs @@ -2,49 +2,96 @@ namespace CodeAlong0412; public class App { - List _dish; - + public List Dish { get; set; } public App() { - _dish = new List() + Dish = new List() { - new Dish("Brød", "Loff", ["Mel",]), - new Dish("Grøt", "Rømmegrøt", ["Milk","Rømme","Ris"]), - new Dish("Pannekaker","Pannekaker er godt", ["Milk","Mel","Egg","Sukker"]), + new Dish(1, + "Loff", + "Hjemmebakt loff kan spises som den er med litt godt smør og pålegg.", + ["Smør","Mel","Gjær","Salt","Melk","Egg", "Valmuefrø"], + ["Brød","Bakverk","Frokost"] + ), + new Dish(2, + "Rømmegrøt", + "Rømmegrøt", + ["Milk","Seterrømme","Mel","Salt"], + ["Frokost", "Middag"] + ), + new Dish(3, + "Pannekaker", + "Pannekaker er godt", + ["Melk","Mel","Egg","Sukker","Salt"], + ["Middag","Dessert"]), + new Dish(4, + "Gulrotrundstykker", + "Gulrot i deigen gjør rundstykkene saftigere og gir en god smak. De passer fint både i matpakken eller som turmat.", + ["Melk","Gjær","Mel","Sukker","Salt","Kardemomme","Gulrot"], + ["Brød","Bakverk", "Lunsj"]) }; AppMenu(); } void AppMenu() { + Console.Clear(); var running = true; while (running) { - //Console.Clear(); - Console.WriteLine("Welcome to the Dishshower!!"); - Console.WriteLine("1. Dish List"); + Console.Clear(); + Console.WriteLine("Velkommen til Oppskrifts appen: "); + Console.WriteLine("1. Vis liste over alle oppskriftene"); + Console.WriteLine("2. Søk på ingrediens"); + Console.WriteLine("3. Søk på kategori"); + Console.WriteLine("q. for å avslutte"); + + var input = Console.ReadLine(); switch(input) { - case "1": - ShowDishNames(); - Thread.Sleep(10000); - break; - case "2": - //var input = Console.ReadLine(); - //SearchIngredients(); + case "1": + ShowDishNamesMenu(); + break; + case "2": + ShowDishByIngredientsMenu(); + break; + case "3": + ShowDishByCategoryMenu(); + break; + case "q": running = false; break; } } } - private void ShowDishNames() + private void ShowDishNamesMenu() { - foreach (var dish in _dish) + Console.Clear(); + Console.WriteLine("Tilgjengelige oppskrifter: "); + foreach (var dish in Dish) { - Console.WriteLine(dish.NameOfDish); + Console.WriteLine($"{dish.DishId}.) {dish.NameOfDish}"); + } + Console.WriteLine("Velg for å se nærmere beskrivelse. Trykk 0 for å gå tilbake"); + var choice = Convert.ToInt32(Console.ReadLine()); + if (choice != 0){ + ShowDish(choice); + } + else + { + Console.WriteLine("Skriv ett tall eller 0 for å gå tilbake."); } - Console.WriteLine(":-D"); } -} \ No newline at end of file + + public void ShowDish(int id) + { + var thisDish = Dish.FirstOrDefault(d => d.DishId == id); + Console.WriteLine($"Navn: {thisDish.NameOfDish}\nBeskrivelse: {thisDish.DescriptionOfDish}"); + Console.ReadLine(); + } + +} + + diff --git a/Codealong/CodeAlong0412/CodeAlong0412/recepies.cs b/Codealong/CodeAlong0412/CodeAlong0412/recepies.cs index b0f0aee..9ef9307 100644 --- a/Codealong/CodeAlong0412/CodeAlong0412/recepies.cs +++ b/Codealong/CodeAlong0412/CodeAlong0412/recepies.cs @@ -2,25 +2,28 @@ namespace CodeAlong0412; public class Dish { - + public int DishId { get; set; } public string NameOfDish { get; set; } public string DescriptionOfDish { get; set; } public string[] Ingredients { get; set; } + public string[] Categories { get; set; } - public Dish(string name, string description, string[] ingredients) + public Dish(int id,string name, string description, string[] ingredients, string[] categories) { + DishId = id; NameOfDish = name; DescriptionOfDish = description; Ingredients = ingredients; + Categories = categories; } - public void ShowDish() + public void ShowDishWithIngredients() { Console.WriteLine($"\nNavn: {NameOfDish}\nBeskrivelse: {DescriptionOfDish}\n"); - Console.WriteLine($"Ingredients: \n{ShowIngredients(Ingredients)}"); + Console.WriteLine($"Ingredients: \n{GetIngredients(Ingredients)}"); } - public string ShowIngredients(string[] ingredientArray) + public string GetIngredients(string[] ingredientArray) { var items = ""; foreach (var ingredient in ingredientArray) @@ -29,7 +32,16 @@ public class Dish } ; return items; } - - + public void ShowDishByIngredientsMenu() + { + Console.Clear(); + Console.WriteLine("Tilgjengelige ingredienter: "); + Console.WriteLine(GetIngredients(Ingredients)); + + } + public void ShowDishByCategoryMenu() + { + Console.Clear(); + } } // search