Litt mer på Codealong

This commit is contained in:
Geir Okkenhaug Jerstad 2024-12-04 19:05:51 +01:00
parent 9c08b65735
commit 9aecbbd1b1
2 changed files with 87 additions and 28 deletions

View file

@ -2,49 +2,96 @@ namespace CodeAlong0412;
public class App public class App
{ {
List<Dish> _dish; public List<Dish> Dish { get; set; }
public App() public App()
{ {
_dish = new List<Dish>() Dish = new List<Dish>()
{ {
new Dish("Brød", "Loff", ["Mel",]), new Dish(1,
new Dish("Grøt", "Rømmegrøt", ["Milk","Rømme","Ris"]), "Loff",
new Dish("Pannekaker","Pannekaker er godt", ["Milk","Mel","Egg","Sukker"]), "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(); AppMenu();
} }
void AppMenu() void AppMenu()
{ {
Console.Clear();
var running = true; var running = true;
while (running) while (running)
{ {
//Console.Clear(); Console.Clear();
Console.WriteLine("Welcome to the Dishshower!!"); Console.WriteLine("Velkommen til Oppskrifts appen: ");
Console.WriteLine("1. Dish List"); 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(); var input = Console.ReadLine();
switch(input) switch(input)
{ {
case "1": case "1":
ShowDishNames(); ShowDishNamesMenu();
Thread.Sleep(10000);
break; break;
case "2": case "2":
//var input = Console.ReadLine(); ShowDishByIngredientsMenu();
//SearchIngredients(); break;
case "3":
ShowDishByCategoryMenu();
break;
case "q":
running = false; running = false;
break; 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(":-D"); 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.");
}
}
public void ShowDish(int id)
{
var thisDish = Dish.FirstOrDefault(d => d.DishId == id);
Console.WriteLine($"Navn: {thisDish.NameOfDish}\nBeskrivelse: {thisDish.DescriptionOfDish}");
Console.ReadLine();
}
} }

View file

@ -2,25 +2,28 @@ namespace CodeAlong0412;
public class Dish public class Dish
{ {
public int DishId { get; set; }
public string NameOfDish { get; set; } public string NameOfDish { get; set; }
public string DescriptionOfDish { get; set; } public string DescriptionOfDish { get; set; }
public string[] Ingredients { 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; NameOfDish = name;
DescriptionOfDish = description; DescriptionOfDish = description;
Ingredients = ingredients; Ingredients = ingredients;
Categories = categories;
} }
public void ShowDish() public void ShowDishWithIngredients()
{ {
Console.WriteLine($"\nNavn: {NameOfDish}\nBeskrivelse: {DescriptionOfDish}\n"); 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 = ""; var items = "";
foreach (var ingredient in ingredientArray) foreach (var ingredient in ingredientArray)
@ -29,7 +32,16 @@ public class Dish
} ; } ;
return items; return items;
} }
public void ShowDishByIngredientsMenu()
{
Console.Clear();
Console.WriteLine("Tilgjengelige ingredienter: ");
Console.WriteLine(GetIngredients(Ingredients));
}
public void ShowDishByCategoryMenu()
{
Console.Clear();
}
} }
// search // search