From e47d956a0e0e78d99676651cbe456a2e52b3b555 Mon Sep 17 00:00:00 2001 From: Henno0701 <1048091@hr.nl> Date: Thu, 11 May 2023 14:17:31 +0200 Subject: [PATCH 01/63] Added parameter canClear, will clear the console --- Logic/MenuLogic.cs | 3 ++- Presentation/CustomerMenu.cs | 2 +- Presentation/Menu.cs | 2 +- Presentation/Reservation/ReservationConsole.cs | 4 ++-- Presentation/UserLogin.cs | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Logic/MenuLogic.cs b/Logic/MenuLogic.cs index cf5c0ee..79734a9 100644 --- a/Logic/MenuLogic.cs +++ b/Logic/MenuLogic.cs @@ -1,6 +1,6 @@ public class MenuLogic { - public static int MultipleChoice(bool canCancel, string symbol, int opl, params string[] options) + public static int MultipleChoice(bool canClear, bool canCancel, string symbol, int opl, params string[] options) { const int startX = 0; const int startY = 10; @@ -16,6 +16,7 @@ public static int MultipleChoice(bool canCancel, string symbol, int opl, params do { + // if (canClear == true) Console.Clear(); Console.Clear(); Welkom.welkom(); Console.WriteLine("\n"); diff --git a/Presentation/CustomerMenu.cs b/Presentation/CustomerMenu.cs index bbb93de..1be57ae 100644 --- a/Presentation/CustomerMenu.cs +++ b/Presentation/CustomerMenu.cs @@ -4,7 +4,7 @@ public class CustomerMenu static public void Start(string username, int id) // ingelogd geef parameter's mee om aan te geven dat de persoon is ingelogd { - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, "Menu bekijken", "Reserveren", "Locatie bekijken", "Log uit"); + int selectedClass = MenuLogic.MultipleChoice(true, true, "", 1, "Menu bekijken", "Reserveren", "Locatie bekijken", "Log uit"); if (selectedClass == 0) { // voor stellen om een foto te laten up poppen van een menu kaart, anders vraag wat precies geshowed moet worden diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index 354be48..67a3290 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -6,7 +6,7 @@ static class Menu static public void Start() { Console.Clear(); - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, "Login", "Menu Kaart", "Reserveren", "Locatie", + int selectedClass = MenuLogic.MultipleChoice(true, true, "○", 1, "Login", "Menu Kaart", "Reserveren", "Locatie", "Registreren", "Stoppen"); if (selectedClass == 0) { diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 0dedf7a..c33f47c 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -83,7 +83,7 @@ public void Reserveren() { string TimeSlotCheck; do { Console.WriteLine("Selecteer een tijdslot:"); - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); + int selectedClass = MenuLogic.MultipleChoice(false, true, "○", 1, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); switch (selectedClass) { case 0: @@ -193,7 +193,7 @@ public void Reserveren(int client_id, string username) { string TimeSlotCheck; do { Console.WriteLine("Selecteer een tijdslot:"); - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); + int selectedClass = MenuLogic.MultipleChoice(false, true, "○", 1, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); switch (selectedClass) { case 0: diff --git a/Presentation/UserLogin.cs b/Presentation/UserLogin.cs index 8cb2203..25023dc 100644 --- a/Presentation/UserLogin.cs +++ b/Presentation/UserLogin.cs @@ -14,7 +14,7 @@ public static void Start() bool passwordNull = true; bool accountNull = true; while(accountNull is true) { - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, $"Email: {email}", $"Wachtwoord: {password}", "", "Login", "Annuleren"); + int selectedClass = MenuLogic.MultipleChoice(true, true, "", 1, $"Email: {email}", $"Wachtwoord: {password}", "", "Login", "Annuleren"); if(selectedClass == 0 && emailNull is true) { Console.WriteLine("Graag uw email invullen."); email = Console.ReadLine(); From 92594a2b5d03970151c10f80c863327adffd62d5 Mon Sep 17 00:00:00 2001 From: Jimmy-Tran Date: Thu, 25 May 2023 12:33:32 +0200 Subject: [PATCH 02/63] ada --- Presentation/Reservation/MyReservation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Presentation/Reservation/MyReservation.cs b/Presentation/Reservation/MyReservation.cs index 60f357a..32356e2 100644 --- a/Presentation/Reservation/MyReservation.cs +++ b/Presentation/Reservation/MyReservation.cs @@ -12,7 +12,7 @@ public static void GetReservationCode() { do { Console.WriteLine($"Vul uw reserveringscode in."); ReservationCode = Console.ReadLine(); - } while (ValidationLogic.CodeExcistsInReservation(ReservationCode) != true); + } while (ValidationLogic.CodeExists(ReservationCode) != true); ShowReservationInfo(ReservationCode); } From 8e54935921225d9f231dc6653825f7cce114430a Mon Sep 17 00:00:00 2001 From: maruf128 Date: Thu, 25 May 2023 13:39:17 +0200 Subject: [PATCH 03/63] nagerecht goed toegevoegd --- Presentation/Show.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Presentation/Show.cs b/Presentation/Show.cs index 3c03c3b..4b72370 100644 --- a/Presentation/Show.cs +++ b/Presentation/Show.cs @@ -35,6 +35,9 @@ public static void Menu() Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, includePrice: true); + Console.WriteLine("\nNagerecht:"); + DisplayMenuItems(menu.Desserts, includePrice: true); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, includePrice: true); break; @@ -46,6 +49,9 @@ public static void Menu() Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, includePrice: true); + Console.WriteLine("\nNagerecht:"); + DisplayMenuItems(menu.Desserts, includePrice: true); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, includePrice: true); break; @@ -86,6 +92,9 @@ public static void Menu(string username, int id) Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, username, id, includePrice: true); + Console.WriteLine("\nNagerecht:"); + DisplayMenuItems(menu.Desserts, username, id, includePrice: true); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, username, id, includePrice: true); break; @@ -97,6 +106,9 @@ public static void Menu(string username, int id) Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, username, id, includePrice: true); + Console.WriteLine("\nNagerecht:"); + DisplayMenuItems(menu.Desserts, username, id, includePrice: true); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, username, id, includePrice: true); break; From c64ecc83d69b9720e7915179fa92e18a814e1126 Mon Sep 17 00:00:00 2001 From: Jimmy-Tran Date: Thu, 25 May 2023 13:43:45 +0200 Subject: [PATCH 04/63] fixed phonenumbers --- Presentation/Reservation/ReservationConsole.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 1e3aba4..113ece0 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -23,6 +23,7 @@ class ReservationConsole public List tables = new List(); bool reserveValid = true; + public string phoneNumber {get; set;} public void Reserveren() { @@ -37,6 +38,22 @@ public void Reserveren() // Change class propperty to given variable after conditions are correct name = nameCheck; + string phoneCheck; + string phonePattern = @"^(?:\+31|0)6\d{8}$"; + do + { + Console.WriteLine("What is your phone number? (+31612345678 or 0612345678)"); + phoneCheck = Console.ReadLine(); + + + if (!Regex.IsMatch(phoneCheck, phonePattern)) + { + Console.WriteLine("Invalid phone number. Please enter a valid phone number."); + } + + } while (!Regex.IsMatch(phoneCheck, phonePattern)); + + string emailCheck; do { From 073df2b47406e0234ba3f41d2f45327dd76d79b0 Mon Sep 17 00:00:00 2001 From: Jimmy-Tran Date: Thu, 25 May 2023 13:43:55 +0200 Subject: [PATCH 05/63] a --- Logic/ReservationLogic.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index 3ea0014..dd94a36 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -305,6 +305,7 @@ public static int GetLastID() return reservations != null ? reservations.Last().ID : 0; } + public static string CodeGenerator() { //Creating object of random class From 7b3c40c22325a3e36f5fe9514ac812dc9f3ac954 Mon Sep 17 00:00:00 2001 From: Henno0701 <1048091@hr.nl> Date: Thu, 25 May 2023 15:15:58 +0200 Subject: [PATCH 06/63] ReservationCode will be send with the Email --- DataSources/reservations.json | 15 +++++++++++++++ Logic/Email.cs | 4 ++-- Presentation/Menu.cs | 1 + Presentation/Reservation/ReservationConsole.cs | 15 +++++++-------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/DataSources/reservations.json b/DataSources/reservations.json index a2b8fc7..1a1338d 100644 --- a/DataSources/reservations.json +++ b/DataSources/reservations.json @@ -13,5 +13,20 @@ "Amt_People": 2, "CourseMenu": 0, "Verified": false + }, + { + "ID": 2, + "ClientNumber": 0, + "Name": "Henno Passchier", + "Email": "henno.passchier@gmail.com", + "Date": "2023-05-26T00:00:00", + "ReservationCode": "QN2G6V", + "TimeSlot": "16:00:00", + "Tables": [ + "4D" + ], + "Amt_People": 4, + "CourseMenu": 0, + "Verified": false } ] \ No newline at end of file diff --git a/Logic/Email.cs b/Logic/Email.cs index 882bfbc..2987143 100644 --- a/Logic/Email.cs +++ b/Logic/Email.cs @@ -5,11 +5,11 @@ using Project_B.Logic; public static class Email { - public static void sendmail(string mail, string name, DateTime date, TimeSpan time) + public static void sendmail(string mail, string name, string ReservationCode, DateTime date, TimeSpan time) { string fromMail = "restaurantjake@gmail.com"; string fromPassword = "luqouzdfclolntnn"; - string randomcode = ReservationLogic.CodeGenerator(); + string randomcode = ReservationCode; MailMessage message = new MailMessage(); message.From = new MailAddress(fromMail); message.Subject = "Reservatie"; diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index 55fb936..99d5fe8 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -23,6 +23,7 @@ static public void Start() { ReservationConsole res = new ReservationConsole(); res.Reserveren(); + Start(); } else if (selectedClass == 3) { diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 1e3aba4..0a8fe99 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -86,6 +86,7 @@ public void Reserveren() bool field4Valid = false; while (field4Valid is false) { + Console.Clear(); string DateCheck; do { @@ -160,7 +161,7 @@ public void Reserveren() { ReservationLogic.AddReservation(id, 0, name, email, date, reservationcode, timeslot, tables, amt_people); Console.WriteLine("Gelukt!"); - Email.sendmail(email, name, date, timeslot); + Email.sendmail(email, name, reservationcode, date, timeslot); Email.warning(); } catch @@ -218,16 +219,14 @@ public void Reserveren(int client_id, string username) // je weet nu hoeveel mensen er zullen komen voeg (maruf) functie's toe om te weten hoeveel het zal kosten - // Gegevens begin = new Gegevens(); - // // nu heb je een lijst met gegevens van de mensen op basis van hoeveel mensen gaan geef je dat door met de int - // List gegevens = begin.Gegevens_krijgen(amt_people); - // Prijs geld = new Prijs(); - // List betalen = geld.Prijs_berekenen(gegevens); - // Console.WriteLine($"intotaal betaal je voor {gegevens.Count} mensen {betalen.Sum()} euro."); + Prijs geld = new Prijs(); + double money = geld.prijs(amt_people); + Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money} euro."); bool field4Valid = false; while (field4Valid is false) { + Console.Clear(); string DateCheck; do { @@ -302,7 +301,7 @@ public void Reserveren(int client_id, string username) { ReservationLogic.AddReservation(id, clientnumber, name, email, date, reservationcode, timeslot, tables, amt_people); Console.WriteLine("Geluk!"); - Email.sendmail(email, name, date, timeslot); + Email.sendmail(email, name, reservationcode, date, timeslot); Email.warning(); } catch (Exception e) From dedbe54de0d1215cea4937f129b26ca574b14597 Mon Sep 17 00:00:00 2001 From: Jimmy-Tran Date: Thu, 25 May 2023 15:16:28 +0200 Subject: [PATCH 07/63] test --- DataSources/menu.json | 2 +- DataSources/reservations.json | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/DataSources/menu.json b/DataSources/menu.json index 480c0fe..54282a9 100644 --- a/DataSources/menu.json +++ b/DataSources/menu.json @@ -1 +1 @@ -{"Starters":[{"ID":1,"Category":null,"Name":"Caesar Salad","Price":7.99},{"ID":2,"Category":null,"Name":"Garlic Bread","Price":4.99}],"Mains":[{"ID":1,"Category":null,"Name":"Spaghetti Bolognese","Price":12.99},{"ID":2,"Category":null,"Name":"Beef Burger","Price":10.99}],"Desserts":[{"ID":1,"Category":null,"Name":"Cheesecake","Price":5.99},{"ID":2,"Category":null,"Name":"Chocolate Brownie","Price":4.99}],"Drinks":[{"ID":1,"Category":null,"Name":"Coca-Cola","Price":2.49},{"ID":2,"Category":null,"Name":"Orange juice","Price":2.50}]} \ No newline at end of file +{"Starters":[{"ID":1,"Category":null,"Name":"Caesar Salad","Price":8.00},{"ID":2,"Category":null,"Name":"Garlic Bread","Price":4.99}],"Mains":[{"ID":1,"Category":null,"Name":"Spaghetti Bolognese","Price":12.99},{"ID":2,"Category":null,"Name":"Beef Burger","Price":10.99}],"Desserts":[{"ID":1,"Category":null,"Name":"Cheesecake","Price":5.99},{"ID":2,"Category":null,"Name":"Chocolate Brownie","Price":4.99}],"Drinks":[{"ID":1,"Category":null,"Name":"Coca-Cola","Price":2.49},{"ID":2,"Category":null,"Name":"Orange juice","Price":2.5}]} \ No newline at end of file diff --git a/DataSources/reservations.json b/DataSources/reservations.json index 0ed17b3..ae44240 100644 --- a/DataSources/reservations.json +++ b/DataSources/reservations.json @@ -11,6 +11,22 @@ "2" ], "Amt_People": 2, + "CourseMenu": null, + "Verified": false + }, + { + "ID": 2, + "ClientNumber": 0, + "Name": "Jimmy Tran", + "Email": "jimmy.trxn@gmail.com", + "Date": "2024-12-05T00:00:00", + "ReservationCode": "UH5C8S", + "TimeSlot": "18:00:00", + "Tables": [ + "4D" + ], + "Amt_People": 4, + "CourseMenu": null, "Verified": false } ] \ No newline at end of file From 99f3e3148fe28ca79a8247c39cf2f59df49318bc Mon Sep 17 00:00:00 2001 From: Henno0701 <1048091@hr.nl> Date: Thu, 25 May 2023 15:23:38 +0200 Subject: [PATCH 08/63] Sleep a sec after coursemenu --- Presentation/Reservation/ReservationConsole.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 0a8fe99..6c7a617 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -82,6 +82,7 @@ public void Reserveren() Prijs geld = new Prijs(); double money = geld.prijs(amt_people); Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money} euro."); + Thread.Sleep(1000); bool field4Valid = false; while (field4Valid is false) @@ -222,6 +223,7 @@ public void Reserveren(int client_id, string username) Prijs geld = new Prijs(); double money = geld.prijs(amt_people); Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money} euro."); + Thread.Sleep(1000); bool field4Valid = false; while (field4Valid is false) From f7c6c5c50258df62b953003bf37b9acc5ba5ca05 Mon Sep 17 00:00:00 2001 From: Henno0701 <1048091@hr.nl> Date: Thu, 25 May 2023 15:25:25 +0200 Subject: [PATCH 09/63] Changes --- Presentation/Reservation/ReservationConsole.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 48b1725..c84db2d 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -99,7 +99,8 @@ public void Reserveren() Prijs geld = new Prijs(); double money = geld.prijs(amt_people); Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money} euro."); - Thread.Sleep(1000); + Console.WriteLine("Druk op iets om verder te gaan..."); + Console.ReadKey(); bool field4Valid = false; while (field4Valid is false) @@ -240,7 +241,8 @@ public void Reserveren(int client_id, string username) Prijs geld = new Prijs(); double money = geld.prijs(amt_people); Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money} euro."); - Thread.Sleep(1000); + Console.WriteLine("Druk op iets om verder te gaan..."); + Console.ReadKey(); bool field4Valid = false; while (field4Valid is false) From 9182814c885091d5db12fb34c1a37dd2553a6e12 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 28 May 2023 14:12:54 +0200 Subject: [PATCH 10/63] ervoor gezorgd dat de admin nu ook Wijn kiest --- DataSources/menu.json | 73 +++++++- Logic/FoodMenu.cs | 19 +- Logic/Food_Aanpassen.cs | 172 ++++++++++-------- .../Reservation/ReservationConsole.cs | 2 +- Presentation/Show.cs | 18 ++ 5 files changed, 198 insertions(+), 86 deletions(-) diff --git a/DataSources/menu.json b/DataSources/menu.json index 54282a9..ffac6c3 100644 --- a/DataSources/menu.json +++ b/DataSources/menu.json @@ -1 +1,72 @@ -{"Starters":[{"ID":1,"Category":null,"Name":"Caesar Salad","Price":8.00},{"ID":2,"Category":null,"Name":"Garlic Bread","Price":4.99}],"Mains":[{"ID":1,"Category":null,"Name":"Spaghetti Bolognese","Price":12.99},{"ID":2,"Category":null,"Name":"Beef Burger","Price":10.99}],"Desserts":[{"ID":1,"Category":null,"Name":"Cheesecake","Price":5.99},{"ID":2,"Category":null,"Name":"Chocolate Brownie","Price":4.99}],"Drinks":[{"ID":1,"Category":null,"Name":"Coca-Cola","Price":2.49},{"ID":2,"Category":null,"Name":"Orange juice","Price":2.5}]} \ No newline at end of file +{ + "Starters": [ + { + "ID": 1, + "Category": null, + "Name": "Caesar Salad", + "Price": 8.0 + }, + { + "ID": 2, + "Category": null, + "Name": "Garlic Bread", + "Price": 4.99 + } + ], + "Mains": [ + { + "ID": 1, + "Category": null, + "Name": "Spaghetti Bolognese", + "Price": 12.99 + }, + { + "ID": 2, + "Category": null, + "Name": "Beef Burger", + "Price": 10.99 + } + ], + "Desserts": [ + { + "ID": 1, + "Category": null, + "Name": "Cheesecake", + "Price": 5.99 + }, + { + "ID": 2, + "Category": null, + "Name": "Chocolate Brownie", + "Price": 4.99 + } + ], + "Drinks": [ + { + "ID": 1, + "Category": null, + "Name": "Coca-Cola", + "Price": 2.49 + }, + { + "ID": 2, + "Category": null, + "Name": "Orange juice", + "Price": 2.5 + } + ], + "Wijn": [ + { + "ID": 1, + "Category": null, + "Name": "Red Wine", + "Price": 15.99 + }, + { + "ID": 3, + "Category": null, + "Name": "Vodka", + "Price": 13.5 + } + ] +} \ No newline at end of file diff --git a/Logic/FoodMenu.cs b/Logic/FoodMenu.cs index e964891..d23eb3e 100644 --- a/Logic/FoodMenu.cs +++ b/Logic/FoodMenu.cs @@ -14,14 +14,14 @@ public class Foodmenu public List Mains { get; set; } public List Desserts { get; set; } public List Drinks { get; set; } - + public List Wijn { get; set; } public Foodmenu() { - // stel ze vast door een nieuwe lijst te maken Starters = new List(); Mains = new List(); Desserts = new List(); Drinks = new List(); + Wijn = new List(); } } @@ -75,7 +75,10 @@ public static Foodmenu ImportFromJson(string filename) { menu.Drinks.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); } - + foreach (var item in data.Wijn) + { + menu.Wijn.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } return menu; } public static void AddMenuItem(Foodmenu menu, MenuItem item, string filename) @@ -103,6 +106,11 @@ public static void AddMenuItem(Foodmenu menu, MenuItem item, string filename) item.Category = null; // set the category property to null menu.Drinks.Add(item); break; + case "Wijn": + item.ID = menu.Wijn.Count > 0 ? menu.Wijn.Max(i => i.ID) + 1 : 1; + item.Category = null; // set the category property to null + menu.Wijn.Add(item); + break; default: throw new Exception("Invalid category specified"); } @@ -129,6 +137,9 @@ public static void RemoveItem(Foodmenu menu, string category, int id, string fil case "Drinks": itemList = menu.Drinks; break; + case "Wijn": + itemList = menu.Wijn; + break; default: throw new Exception("Invalid category specified"); } @@ -153,7 +164,7 @@ public static void RemoveItem(Foodmenu menu, string category, int id, string fil public static void SaveMenuToJson(Foodmenu menu, string filename) { // Serialize the menu to JSON and write it to the file - string json = JsonConvert.SerializeObject(menu); + string json = JsonConvert.SerializeObject(menu, Formatting.Indented); File.WriteAllText(filename, json); } diff --git a/Logic/Food_Aanpassen.cs b/Logic/Food_Aanpassen.cs index 6daab66..6dd7b43 100644 --- a/Logic/Food_Aanpassen.cs +++ b/Logic/Food_Aanpassen.cs @@ -18,7 +18,10 @@ public static void EditMenu(string username, int id) RemoveItem(username, id); break; case "3": - ChangeItem(username, id); + Console.WriteLine("Functie momenteel buiten werking"); + Console.ReadKey(); + ManagerMenu.Admin_menu(username, id);// zodat je terug gaat + // ChangeItem(username, id); break; case "T": ManagerMenu.Admin_menu(username, id);// zodat je terug gaat @@ -31,7 +34,7 @@ public static void EditMenu(string username, int id) } public static void AddItem(string username, int id) { - Console.WriteLine("Voer de categorie in:(Starters/Mains/Desserts/Drinks)"); + Console.WriteLine("Voer de categorie in: (Starters/Mains/Desserts/Drinks/Wijn)"); Console.WriteLine("*Hoofdletter gevoelig"); string category = Console.ReadLine(); @@ -42,6 +45,7 @@ public static void AddItem(string username, int id) case "Mains": case "Desserts": case "Drinks": + case "Wijn": break; default: Console.WriteLine("Ongeldige categorie. Kies opnieuw."); @@ -87,18 +91,18 @@ public static void AddItem(string username, int id) public static void RemoveItem(string username, int user_id) { - // ask for the category from which the user wants to remove an item - Console.WriteLine("Voer de categorie in: (Starters/Mains/Desserts/Drinks)"); + Console.WriteLine("Voer de categorie in: (Starters/Mains/Desserts/Drinks/Wijn)"); Console.WriteLine("*Hoofdletter gevoelig"); string category = Console.ReadLine(); string filenaam = @"DataSources/menu.json"; - // check if the category is valid + // Check if the category is valid switch (category) { case "Starters": case "Mains": case "Desserts": case "Drinks": + case "Wijn": break; default: Console.WriteLine("Ongeldige categorie. Kies opnieuw."); @@ -106,6 +110,7 @@ public static void RemoveItem(string username, int user_id) return; } + // ask for the ID of the item the user wants to remove Console.WriteLine("Voer de ID in van het item dat je wilt verwijderen:"); int id = int.Parse(Console.ReadLine()); @@ -129,6 +134,9 @@ public static void RemoveItem(string username, int user_id) case "Drinks": itemToRemove = menu.Drinks.FirstOrDefault(i => i.ID == id); break; + case "Wijn": + itemToRemove = menu.Wijn.FirstOrDefault(i => i.ID == id); + break; } // if the item was not found, notify the user and return @@ -153,96 +161,100 @@ public static void RemoveItem(string username, int user_id) case "Drinks": menu.Drinks.Remove(itemToRemove); break; + case "Wijn": + menu.Wijn.Remove(itemToRemove); + break; } MenuImporter.SaveMenuToJson(menu, filenaam); Console.WriteLine($"Item {itemToRemove.Name} met ID {itemToRemove.ID} is succesvol verwijderd uit de categorie {category}."); ManagerMenu.Admin_menu(username, user_id);// zodat je terug gaat } - public static void ChangeItem(string username, int user_id) - { - // ask for the category of the item to be changed - Console.WriteLine("Voer de categorie in: (Starters/Mains/Desserts/Drinks)"); - Console.WriteLine("*Hoofdletter gevoelig"); - string category = Console.ReadLine(); + // na vragen bij PO of item aanpas wel moest, zo ja pas hem ook aan voor wijn + // public static void ChangeItem(string username, int user_id) + // { + // // ask for the category of the item to be changed + // Console.WriteLine("Voer de categorie in: (Starters/Mains/Desserts/Drinks)"); + // Console.WriteLine("*Hoofdletter gevoelig"); + // string category = Console.ReadLine(); - // check if the category is valid - switch (category) - { - case "Starters": - case "Mains": - case "Desserts": - case "Drinks": - break; - default: - Console.WriteLine("Ongeldige categorie. Kies opnieuw."); - ChangeItem(username, user_id); - return; - } + // // check if the category is valid + // switch (category) + // { + // case "Starters": + // case "Mains": + // case "Desserts": + // case "Drinks": + // break; + // default: + // Console.WriteLine("Ongeldige categorie. Kies opnieuw."); + // ChangeItem(username, user_id); + // return; + // } - // ask for the ID of the item to be changed - Console.WriteLine("Voer de ID in van het item dat je wilt aanpassen:"); - int id = int.Parse(Console.ReadLine()); + // // ask for the ID of the item to be changed + // Console.WriteLine("Voer de ID in van het item dat je wilt aanpassen:"); + // int id = int.Parse(Console.ReadLine()); - // get the menu from the JSON file - string filenaam = @"DataSources/menu.json"; - Foodmenu menu = MenuImporter.ImportFromJson(filenaam); + // // get the menu from the JSON file + // string filenaam = @"DataSources/menu.json"; + // Foodmenu menu = MenuImporter.ImportFromJson(filenaam); - // find the item in the menu based on the category and ID - MenuItem itemToChange = null; - switch (category) - { - case "Starters": - itemToChange = menu.Starters.FirstOrDefault(i => i.ID == id); - break; - case "Mains": - itemToChange = menu.Mains.FirstOrDefault(i => i.ID == id); - break; - case "Desserts": - itemToChange = menu.Desserts.FirstOrDefault(i => i.ID == id); - break; - case "Drinks": - itemToChange = menu.Drinks.FirstOrDefault(i => i.ID == id); - break; - } + // // find the item in the menu based on the category and ID + // MenuItem itemToChange = null; + // switch (category) + // { + // case "Starters": + // itemToChange = menu.Starters.FirstOrDefault(i => i.ID == id); + // break; + // case "Mains": + // itemToChange = menu.Mains.FirstOrDefault(i => i.ID == id); + // break; + // case "Desserts": + // itemToChange = menu.Desserts.FirstOrDefault(i => i.ID == id); + // break; + // case "Drinks": + // itemToChange = menu.Drinks.FirstOrDefault(i => i.ID == id); + // break; + // } - // if the item was not found, notify the user and return - if (itemToChange == null) - { - Console.WriteLine($"Item met ID {id} kon niet worden gevonden in de categorie {category}."); - return; - } + // // if the item was not found, notify the user and return + // if (itemToChange == null) + // { + // Console.WriteLine($"Item met ID {id} kon niet worden gevonden in de categorie {category}."); + // return; + // } - // ask for the new name - Console.WriteLine($"Huidige naam: {itemToChange.Name}"); - Console.WriteLine("Voer de nieuwe naam in:"); - string name = Console.ReadLine(); + // // ask for the new name + // Console.WriteLine($"Huidige naam: {itemToChange.Name}"); + // Console.WriteLine("Voer de nieuwe naam in:"); + // string name = Console.ReadLine(); - // check if the new name is not empty - if (string.IsNullOrWhiteSpace(name)) - { - Console.WriteLine("Naam mag niet leeg zijn. Kies opnieuw."); - ChangeItem(username, user_id); - return; - } + // // check if the new name is not empty + // if (string.IsNullOrWhiteSpace(name)) + // { + // Console.WriteLine("Naam mag niet leeg zijn. Kies opnieuw."); + // ChangeItem(username, user_id); + // return; + // } - // ask for the new price - Console.WriteLine($"Huidige prijs: {itemToChange.Price}"); - Console.WriteLine("Voer de nieuwe prijs in:"); - if (!decimal.TryParse(Console.ReadLine(), out decimal price)) - { - Console.WriteLine("Ongeldige prijs. Kies opnieuw."); - ChangeItem(username, user_id); - return; - } + // // ask for the new price + // Console.WriteLine($"Huidige prijs: {itemToChange.Price}"); + // Console.WriteLine("Voer de nieuwe prijs in:"); + // if (!decimal.TryParse(Console.ReadLine(), out decimal price)) + // { + // Console.WriteLine("Ongeldige prijs. Kies opnieuw."); + // ChangeItem(username, user_id); + // return; + // } - // update the item in the menu and save the changes to the JSON file - itemToChange.Name = name; - itemToChange.Price = price; - MenuImporter.SaveMenuToJson(menu, filenaam); + // // update the item in the menu and save the changes to the JSON file + // itemToChange.Name = name; + // itemToChange.Price = price; + // MenuImporter.SaveMenuToJson(menu, filenaam); - Console.WriteLine($"Item met ID {itemToChange.ID} is succesvol aangepast in de categorie {category}."); - ManagerMenu.Admin_menu(username, user_id);// zodat je terug gaat - } + // Console.WriteLine($"Item met ID {itemToChange.ID} is succesvol aangepast in de categorie {category}."); + // ManagerMenu.Admin_menu(username, user_id);// zodat je terug gaat + // } } \ No newline at end of file diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index c84db2d..be66fda 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -23,7 +23,7 @@ class ReservationConsole public List tables = new List(); bool reserveValid = true; - public string phoneNumber {get; set;} + public string phoneNumber { get; set; } public void Reserveren() { diff --git a/Presentation/Show.cs b/Presentation/Show.cs index 4b72370..4840823 100644 --- a/Presentation/Show.cs +++ b/Presentation/Show.cs @@ -24,6 +24,9 @@ public static void Menu() Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, includePrice: true); + Console.WriteLine("\nWijn:"); + DisplayMenuItems(menu.Wijn, includePrice: false); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, includePrice: true); break; @@ -38,6 +41,9 @@ public static void Menu() Console.WriteLine("\nNagerecht:"); DisplayMenuItems(menu.Desserts, includePrice: true); + Console.WriteLine("\nWijn:"); + DisplayMenuItems(menu.Wijn, includePrice: false); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, includePrice: true); break; @@ -52,6 +58,9 @@ public static void Menu() Console.WriteLine("\nNagerecht:"); DisplayMenuItems(menu.Desserts, includePrice: true); + Console.WriteLine("\nWijn:"); + DisplayMenuItems(menu.Wijn, includePrice: false); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, includePrice: true); break; @@ -81,6 +90,9 @@ public static void Menu(string username, int id) Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, username, id, includePrice: true); + Console.WriteLine("\nWijn:"); + DisplayMenuItems(menu.Wijn, username, id, includePrice: false); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, username, id, includePrice: true); break; @@ -95,6 +107,9 @@ public static void Menu(string username, int id) Console.WriteLine("\nNagerecht:"); DisplayMenuItems(menu.Desserts, username, id, includePrice: true); + Console.WriteLine("\nWijn:"); + DisplayMenuItems(menu.Wijn, username, id, includePrice: false); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, username, id, includePrice: true); break; @@ -109,6 +124,9 @@ public static void Menu(string username, int id) Console.WriteLine("\nNagerecht:"); DisplayMenuItems(menu.Desserts, username, id, includePrice: true); + Console.WriteLine("\nWijn:"); + DisplayMenuItems(menu.Wijn, username, id, includePrice: false); + Console.WriteLine("\nDrinks:"); DisplayMenuItems(menu.Drinks, username, id, includePrice: true); break; From fe1d8977a746e72b6ede585f8d1785fca5de195c Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 28 May 2023 14:16:08 +0200 Subject: [PATCH 11/63] ervoor gezorgd dat food ook datamodels heeft --- DataModels/FoodModel.cs | 26 ++++++++++++++++++++++++++ Logic/FoodMenu.cs | 25 ------------------------- 2 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 DataModels/FoodModel.cs diff --git a/DataModels/FoodModel.cs b/DataModels/FoodModel.cs new file mode 100644 index 0000000..dc1903e --- /dev/null +++ b/DataModels/FoodModel.cs @@ -0,0 +1,26 @@ +// data models voor de voedsel +public class MenuItem // losse item class +{ + public int ID { get; set; } + public string Category { get; set; } + public string Name { get; set; } + public decimal Price { get; set; } +} +public class Foodmenu +{ + // maak nu een lijst voor iedere gang en drinken + public List Starters { get; set; } + public List Mains { get; set; } + public List Desserts { get; set; } + public List Drinks { get; set; } + public List Wijn { get; set; } + public Foodmenu() + { + Starters = new List(); + Mains = new List(); + Desserts = new List(); + Drinks = new List(); + Wijn = new List(); + } + +} \ No newline at end of file diff --git a/Logic/FoodMenu.cs b/Logic/FoodMenu.cs index d23eb3e..4024523 100644 --- a/Logic/FoodMenu.cs +++ b/Logic/FoodMenu.cs @@ -1,30 +1,5 @@ using System.IO; using Newtonsoft.Json; -public class MenuItem // losse item class -{ - public int ID { get; set; } - public string Category { get; set; } - public string Name { get; set; } - public decimal Price { get; set; } -} -public class Foodmenu -{ - // maak nu een lijst voor iedere gang en drinken - public List Starters { get; set; } - public List Mains { get; set; } - public List Desserts { get; set; } - public List Drinks { get; set; } - public List Wijn { get; set; } - public Foodmenu() - { - Starters = new List(); - Mains = new List(); - Desserts = new List(); - Drinks = new List(); - Wijn = new List(); - } - -} // maak de menu importer public class MenuImporter { From 4c0cad9521faa10030d838ab8187d9b070d4edc8 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 30 May 2023 10:46:18 +0200 Subject: [PATCH 12/63] Ervoor gezorgd dat 4 gangen menu eigen cat heeft --- DataModels/FoodModel.cs | 2 ++ DataSources/menu.json | 73 +---------------------------------------- Logic/FoodMenu.cs | 12 +++++++ Logic/Food_Aanpassen.cs | 12 +++++-- Presentation/Show.cs | 18 ++++++---- 5 files changed, 37 insertions(+), 80 deletions(-) diff --git a/DataModels/FoodModel.cs b/DataModels/FoodModel.cs index dc1903e..fc452d5 100644 --- a/DataModels/FoodModel.cs +++ b/DataModels/FoodModel.cs @@ -10,6 +10,7 @@ public class Foodmenu { // maak nu een lijst voor iedere gang en drinken public List Starters { get; set; } + public List Soups { get; set; } public List Mains { get; set; } public List Desserts { get; set; } public List Drinks { get; set; } @@ -17,6 +18,7 @@ public class Foodmenu public Foodmenu() { Starters = new List(); + Soups = new List(); Mains = new List(); Desserts = new List(); Drinks = new List(); diff --git a/DataSources/menu.json b/DataSources/menu.json index ffac6c3..56826de 100644 --- a/DataSources/menu.json +++ b/DataSources/menu.json @@ -1,72 +1 @@ -{ - "Starters": [ - { - "ID": 1, - "Category": null, - "Name": "Caesar Salad", - "Price": 8.0 - }, - { - "ID": 2, - "Category": null, - "Name": "Garlic Bread", - "Price": 4.99 - } - ], - "Mains": [ - { - "ID": 1, - "Category": null, - "Name": "Spaghetti Bolognese", - "Price": 12.99 - }, - { - "ID": 2, - "Category": null, - "Name": "Beef Burger", - "Price": 10.99 - } - ], - "Desserts": [ - { - "ID": 1, - "Category": null, - "Name": "Cheesecake", - "Price": 5.99 - }, - { - "ID": 2, - "Category": null, - "Name": "Chocolate Brownie", - "Price": 4.99 - } - ], - "Drinks": [ - { - "ID": 1, - "Category": null, - "Name": "Coca-Cola", - "Price": 2.49 - }, - { - "ID": 2, - "Category": null, - "Name": "Orange juice", - "Price": 2.5 - } - ], - "Wijn": [ - { - "ID": 1, - "Category": null, - "Name": "Red Wine", - "Price": 15.99 - }, - { - "ID": 3, - "Category": null, - "Name": "Vodka", - "Price": 13.5 - } - ] -} \ No newline at end of file +{"Starters":[{"ID":1,"Category":null,"Name":"Caesar Salad","Price":8.0},{"ID":2,"Category":null,"Name":"Garlic Bread","Price":4.99}],"Soups":[{"ID":1,"Category":null,"Name":"Tomaten soep","Price":12.50}],"Mains":[{"ID":1,"Category":null,"Name":"Spaghetti Bolognese","Price":12.99},{"ID":2,"Category":null,"Name":"Beef Burger","Price":10.99}],"Desserts":[{"ID":1,"Category":null,"Name":"Cheesecake","Price":5.99},{"ID":2,"Category":null,"Name":"Chocolate Brownie","Price":4.99},{"ID":3,"Category":null,"Name":"appeltaart","Price":4.5}],"Drinks":[{"ID":1,"Category":null,"Name":"Coca-Cola","Price":2.49},{"ID":2,"Category":null,"Name":"Orange juice","Price":2.5}],"Wijn":[{"ID":3,"Category":null,"Name":"Vodka","Price":13.5},{"ID":4,"Category":null,"Name":"Barcardi","Price":4.5}]} \ No newline at end of file diff --git a/Logic/FoodMenu.cs b/Logic/FoodMenu.cs index 4024523..fa31bf5 100644 --- a/Logic/FoodMenu.cs +++ b/Logic/FoodMenu.cs @@ -54,6 +54,10 @@ public static Foodmenu ImportFromJson(string filename) { menu.Wijn.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); } + foreach (var item in data.Soups) + { + menu.Soups.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } return menu; } public static void AddMenuItem(Foodmenu menu, MenuItem item, string filename) @@ -66,6 +70,11 @@ public static void AddMenuItem(Foodmenu menu, MenuItem item, string filename) item.Category = null; // set the category property to null menu.Starters.Add(item); break; + case "Soups": + item.ID = menu.Soups.Count > 0 ? menu.Soups.Max(i => i.ID) + 1 : 1; + item.Category = null; // set the category property to null + menu.Soups.Add(item); + break; case "Mains": item.ID = menu.Mains.Count > 0 ? menu.Mains.Max(i => i.ID) + 1 : 1; item.Category = null; // set the category property to null @@ -115,6 +124,9 @@ public static void RemoveItem(Foodmenu menu, string category, int id, string fil case "Wijn": itemList = menu.Wijn; break; + case "Soups": + itemList = menu.Wijn; + break; default: throw new Exception("Invalid category specified"); } diff --git a/Logic/Food_Aanpassen.cs b/Logic/Food_Aanpassen.cs index 6dd7b43..4e59dfb 100644 --- a/Logic/Food_Aanpassen.cs +++ b/Logic/Food_Aanpassen.cs @@ -34,7 +34,7 @@ public static void EditMenu(string username, int id) } public static void AddItem(string username, int id) { - Console.WriteLine("Voer de categorie in: (Starters/Mains/Desserts/Drinks/Wijn)"); + Console.WriteLine("Voer de categorie in: (Starters/Soups/Mains/Desserts/Drinks/Wijn)"); Console.WriteLine("*Hoofdletter gevoelig"); string category = Console.ReadLine(); @@ -42,6 +42,7 @@ public static void AddItem(string username, int id) switch (category) { case "Starters": + case "Soups": case "Mains": case "Desserts": case "Drinks": @@ -91,7 +92,7 @@ public static void AddItem(string username, int id) public static void RemoveItem(string username, int user_id) { - Console.WriteLine("Voer de categorie in: (Starters/Mains/Desserts/Drinks/Wijn)"); + Console.WriteLine("Voer de categorie in: (Starters/Soups/Mains/Desserts/Drinks/Wijn)"); Console.WriteLine("*Hoofdletter gevoelig"); string category = Console.ReadLine(); string filenaam = @"DataSources/menu.json"; @@ -99,6 +100,7 @@ public static void RemoveItem(string username, int user_id) switch (category) { case "Starters": + case "Soups": case "Mains": case "Desserts": case "Drinks": @@ -125,6 +127,9 @@ public static void RemoveItem(string username, int user_id) case "Starters": itemToRemove = menu.Starters.FirstOrDefault(i => i.ID == id); break; + case "Soups": + itemToRemove = menu.Soups.FirstOrDefault(i => i.ID == id); + break; case "Mains": itemToRemove = menu.Mains.FirstOrDefault(i => i.ID == id); break; @@ -152,6 +157,9 @@ public static void RemoveItem(string username, int user_id) case "Starters": menu.Starters.Remove(itemToRemove); break; + case "Soups": + menu.Soups.Remove(itemToRemove); + break; case "Mains": menu.Mains.Remove(itemToRemove); break; diff --git a/Presentation/Show.cs b/Presentation/Show.cs index 4840823..1919f11 100644 --- a/Presentation/Show.cs +++ b/Presentation/Show.cs @@ -8,9 +8,9 @@ public static void Menu() Console.WriteLine("╔════════════════════════════════════════╗"); Console.WriteLine("║ Restaurant Menu ║"); Console.WriteLine("╚════════════════════════════════════════╝"); - Console.WriteLine("2 Gangen menu ......1x Hoofdgerecht en 1x Nagerecht .........................15,50"); - Console.WriteLine("3 Ganger menu ......1x Voorgerecht, 1x Hoofdgerecht en 1x Nagerecht .........20,50"); - Console.WriteLine("4 Ganger menu ......2x Voorgerecht, 1x Hoofdgerecht, 1x Nagerecht ...........25,50"); + Console.WriteLine("2 Gangen menu ......1x Hoofdgerecht en 1x Nagerecht .................................15,50"); + Console.WriteLine("3 Ganger menu ......1x Voorgerecht, 1x Hoofdgerecht en 1x Nagerecht .................20,50"); + Console.WriteLine("4 Ganger menu ......1x Voorgerecht, 1x Soep 1x Hoofdgerecht, 1x Nagerecht ...........25,50"); // maak functie om te kiezen welke menu de klant wilt int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "2 Gangen menu", "3 Gangen menu", "4 Gangen menu"); @@ -52,6 +52,9 @@ public static void Menu() Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, includePrice: true); + Console.WriteLine("\nSoepen:"); + DisplayMenuItems(menu.Soups, includePrice: true); + Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, includePrice: true); @@ -74,9 +77,9 @@ public static void Menu(string username, int id) Console.WriteLine("╔════════════════════════════════════════╗"); Console.WriteLine("║ Restaurant Menu ║"); Console.WriteLine("╚════════════════════════════════════════╝"); - Console.WriteLine("2 Gangen menu ......1x Hoofdgerecht en 1x Nagerecht .........................15,50"); - Console.WriteLine("3 Ganger menu ......1x Voorgerecht, 1x Hoofdgerecht en 1x Nagerecht .........20,50"); - Console.WriteLine("4 Ganger menu ......2x Voorgerecht, 1x Hoofdgerecht, 1x Nagerecht ...........25,50"); + Console.WriteLine("2 Gangen menu ......1x Hoofdgerecht en 1x Nagerecht .................................15,50"); + Console.WriteLine("3 Ganger menu ......1x Voorgerecht, 1x Hoofdgerecht en 1x Nagerecht .................20,50"); + Console.WriteLine("4 Ganger menu ......1x Voorgerecht, 1x Soep 1x Hoofdgerecht, 1x Nagerecht ...........25,50"); // maak functie om te kiezen welke menu de klant wilt int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "2 Gangen menu", "3 Gangen menu", "4 Gangen menu"); @@ -118,6 +121,9 @@ public static void Menu(string username, int id) Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, username, id, includePrice: true); + Console.WriteLine("\nSoepen:"); + DisplayMenuItems(menu.Soups, username, id, includePrice: true); + Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, username, id, includePrice: true); From 8c2332594dda6a32d9fc054b4c7486c2120d76ac Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 30 May 2023 11:09:31 +0200 Subject: [PATCH 13/63] Wijn arrangement word nu ook berekent met logics --- Logic/Prijs.cs | 41 +++++++++++++++++-- .../Reservation/ReservationConsole.cs | 2 +- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Logic/Prijs.cs b/Logic/Prijs.cs index 4004d1c..ef3c74a 100644 --- a/Logic/Prijs.cs +++ b/Logic/Prijs.cs @@ -7,6 +7,7 @@ public class Prijs // Field for the discount percentage public double discount = 0.1; + public double wijn_arrangement = 3.50; // Method to calculate the price public double prijs(int aantal) @@ -31,10 +32,36 @@ public double prijs(int aantal) break; } - // Prompt for the number of people under 12 - Console.WriteLine($"Hoeveel van de {aantal} personen zijn 12 jaar of jonger?"); - int onder_12 = Convert.ToInt32(Console.ReadLine()); + bool validInput = false; + int onder_12 = 0; + int wineCount = 0; + while (!validInput) + { + Console.WriteLine($"Hoeveel van de {aantal} personen zijn 12 jaar of jonger?"); + onder_12 = Convert.ToInt32(Console.ReadLine()); + + Console.WriteLine($"Hoeveel van de {aantal} personen willen het wijnarrangement ({wijn_arrangement})?"); + wineCount = Convert.ToInt32(Console.ReadLine()); + if (onder_12 > aantal) + { + Console.WriteLine("Het aantal personen jonger dan 12 kan niet groter zijn dan het totale aantal personen."); + } + else if (wineCount > aantal) + { + Console.WriteLine("Het aantal personen dat wijn wil nemen kan niet groter zijn dan het totale aantal personen."); + } + else if (onder_12 + wineCount > aantal) + { + Console.WriteLine("Het totale aantal personen jonger dan 12 en het aantal personen dat wijn wil nemen kan niet groter zijn dan het totale aantal personen."); + } + else + { + validInput = true; + // All numbers are logical, continue with the rest of your code + // ... + } + } double menuPrijs = 0.0; // Calculate the price based on the chosen menu @@ -60,7 +87,13 @@ public double prijs(int aantal) // Apply the discount for people under 12 double korting = menuPrijs * onder_12 * discount; totPrijs -= korting; - + // zorg nu dat je de wijn erbij doet + if (wineCount > 0) + { + // indien er dus wel mensen zijn met wijn + double wijnprijs = wijn_arrangement * wineCount; + totPrijs += wijnprijs; + } return totPrijs; } } diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index be66fda..766ccf0 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -240,7 +240,7 @@ public void Reserveren(int client_id, string username) // je weet nu hoeveel mensen er zullen komen voeg (maruf) functie's toe om te weten hoeveel het zal kosten Prijs geld = new Prijs(); double money = geld.prijs(amt_people); - Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money} euro."); + Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money:f2} euro."); Console.WriteLine("Druk op iets om verder te gaan..."); Console.ReadKey(); From 97befe38a43dce7c1d831f6442a37d98d49925ae Mon Sep 17 00:00:00 2001 From: Henno0701 <1048091@hr.nl> Date: Thu, 1 Jun 2023 13:23:13 +0200 Subject: [PATCH 14/63] Added a tuple --- DataSources/accounts.json | 2 +- Logic/ReservationLogic.cs | 28 +++++-------------- Presentation/Reservation/MyReservation.cs | 16 +---------- .../Reservation/ReservationConsole.cs | 16 ++++++++--- Presentation/Show.cs | 2 +- 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/DataSources/accounts.json b/DataSources/accounts.json index b8b109c..e6ee348 100644 --- a/DataSources/accounts.json +++ b/DataSources/accounts.json @@ -58,7 +58,7 @@ { "id": 9, "emailAddress": "henno.passchier@gmail.com", - "password": "abc", + "password": "Abc123!", "fullName": "Henno Passchier", "level": 0 } diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index 1bd42a0..d7a3947 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -191,26 +191,6 @@ public static bool VerifyingReservation(int _ID) { return false; } } - - public static bool AccessReservationSimulation(string _ReservationCode) { - try { - //Get reservations from other function - List reservations = GetReservations(); - - DateTime DateNow = DateTime.Now; - - //Look in reservations for the reservationcode and if it is this day. - if (reservations.Any(r => r.ReservationCode == _ReservationCode && r.Date == DateNow.Date)) { - return true; - } else { - return false; - } - } - catch (Exception ex) { - Console.WriteLine($"Kon geen reserveringen ophalen!"); - return false; - } - } public static void UpdateTableAvailability(List TablesList) { @@ -300,10 +280,16 @@ public static void ShowTables() public static int GetLastID() { + List> ids = new (); //Get reservations from other function List reservations = GetReservations(); - return reservations.Count() != 0 ? reservations.Last().ID : 0; + foreach (ReservationModel reservation in reservations) { + ids.Add(Tuple.Create(reservation.ID)); + } + + + return reservations.Count() != 0 ? ids.Max(x => x.Item1) : 0; } public static string CodeGenerator() diff --git a/Presentation/Reservation/MyReservation.cs b/Presentation/Reservation/MyReservation.cs index bc110e3..b5a2c59 100644 --- a/Presentation/Reservation/MyReservation.cs +++ b/Presentation/Reservation/MyReservation.cs @@ -39,11 +39,6 @@ static public void ShowReservationInfo( string _ReservationCode) { if (reservation.ReservationCode == _ReservationCode) { //Search in the list if the Code excist Found = true; // set Found to true so it wont show NotFound - if (ReservationLogic.AccessReservationSimulation(_ReservationCode) == true) { - // Start Reservation Simulation - break; - } else { - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] {"Reservatie Informatie:", $"Datum: {reservation.Date.ToString("dddd, dd MMMM yyyy")}", $"Tijd: {reservation.TimeSlot.ToString(@"hh\:mm")}", $"Reserverings Code: {reservation.ReservationCode}"}, "Bevestig reservering", "Annuleer reservering", "Terug"); switch (selectedClass) { @@ -116,8 +111,6 @@ static public void ShowReservationInfo( string _ReservationCode) { } } } - - } if (Found != true) { Console.WriteLine("\nGeen reservering gevonden, heeft u de juiste code ingevoerd?\nDruk op iets om door te gaan..."); @@ -138,11 +131,6 @@ static public void ShowReservationInfo(string username, int id, string _Reservat if (reservation.ReservationCode == _ReservationCode) { //Search in the list if the Code excist Found = true; // set Found to true so it wont show NotFound - if (ReservationLogic.AccessReservationSimulation(_ReservationCode) == true) { - // Start Reservation Simulation - break; - } else { - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] {"Reservatie Informatie:", $"Datum: {reservation.Date.ToString("dddd, dd MMMM yyyy")}", $"Tijd: {reservation.TimeSlot.ToString(@"hh\:mm")}", $"Reserverings Code: {reservation.ReservationCode}"}, "Bevestig reservering", "Annuleer reservering", "Terug"); switch (selectedClass) { @@ -215,11 +203,9 @@ static public void ShowReservationInfo(string username, int id, string _Reservat } } } - - } if (Found != true) { - Console.WriteLine("\nGeen reservering gevonden, heeft u de juiste code ingevoerd?\nDruk op iets om door te gaan..."); + Console.WriteLine("\nGeen reservering gevonden\nDruk op iets om door te gaan..."); Console.ReadKey(); CustomerMenu.Start(username, id); diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index c84db2d..ce42530 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -38,21 +38,25 @@ public void Reserveren() // Change class propperty to given variable after conditions are correct name = nameCheck; + Console.Clear(); + string phoneCheck; string phonePattern = @"^(?:\+31|0)6\d{8}$"; + do { - Console.WriteLine("What is your phone number? (+31612345678 or 0612345678)"); + Console.WriteLine("(Optioneel) Wat is uw telefoon nummer? (+31612345678 or 0612345678)"); phoneCheck = Console.ReadLine(); if (!Regex.IsMatch(phoneCheck, phonePattern)) { - Console.WriteLine("Invalid phone number. Please enter a valid phone number."); + Console.WriteLine("Dit is geen valide telefoon nummer!"); } - } while (!Regex.IsMatch(phoneCheck, phonePattern)); + } while (!Regex.IsMatch(phoneCheck, phonePattern) && phoneCheck == null); + Console.Clear(); string emailCheck; do @@ -63,6 +67,7 @@ public void Reserveren() email = emailCheck; + Console.Clear(); int amountPeopleCheck; do @@ -98,7 +103,8 @@ public void Reserveren() // je weet nu hoeveel mensen er zullen komen voeg (maruf) functie's toe om te weten hoeveel het zal kosten Prijs geld = new Prijs(); double money = geld.prijs(amt_people); - Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money} euro."); + + Console.WriteLine($"\nIn totaal betaal je voor {amt_people} mensen {money} euro."); Console.WriteLine("Druk op iets om verder te gaan..."); Console.ReadKey(); @@ -214,6 +220,8 @@ public void Reserveren(int client_id, string username) amt_people = amountPeopleCheck; + Console.Clear(); + if (amountPeopleCheck > 6) { int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { "We zien dat u meer dan 6 personen heeft. Wilt u nogsteeds verder gaan met de reservering?", "Klik dan op \"Verder gaan\" en verander de hoeveelheid personen naar 6 of lager! Daarna heeft u de mogelijkheid om nog een reservering te maken met de overige personen.", "U kunt ook met ons contact opnemen via telefoon 063828192" }, "Reservering annuleren", "Verder gaan"); diff --git a/Presentation/Show.cs b/Presentation/Show.cs index 4b72370..63fe4eb 100644 --- a/Presentation/Show.cs +++ b/Presentation/Show.cs @@ -154,7 +154,7 @@ public static void ShowLocation(Location location) Console.WriteLine("Adres: " + location.Address); Console.WriteLine("Telefoon: " + location.Phone); Console.WriteLine("E-mail: " + location.Email); - Console.WriteLine("Openingstijden:"); + Console.WriteLine("\nOpeningstijden:"); Console.WriteLine("zondag\t\t" + location.OpeningHours["zondag"]); Console.WriteLine("maandag\t\t" + location.OpeningHours["maandag"]); Console.WriteLine("dinsdag\t\t" + location.OpeningHours["dinsdag"]); From 3d8bdc771d9223390e6eff6471331e855c4678da Mon Sep 17 00:00:00 2001 From: maruf128 Date: Mon, 5 Jun 2023 08:10:49 +0200 Subject: [PATCH 15/63] email voor reservatie bij admin, edit food deleted --- Logic/Email.cs | 2 +- Logic/Food_Aanpassen.cs | 14 +- .../Reservation/ReservationConsole.cs | 10 +- Presentation/Reservation/ReservationView.cs | 169 ++++++++++++------ 4 files changed, 124 insertions(+), 71 deletions(-) diff --git a/Logic/Email.cs b/Logic/Email.cs index 2987143..b2d9d06 100644 --- a/Logic/Email.cs +++ b/Logic/Email.cs @@ -3,7 +3,7 @@ using System.Net.Mail; using System.Threading.Tasks; using Project_B.Logic; -public static class Email +public static class EmailFunction { public static void sendmail(string mail, string name, string ReservationCode, DateTime date, TimeSpan time) { diff --git a/Logic/Food_Aanpassen.cs b/Logic/Food_Aanpassen.cs index 4e59dfb..f044e7e 100644 --- a/Logic/Food_Aanpassen.cs +++ b/Logic/Food_Aanpassen.cs @@ -5,7 +5,7 @@ public static void EditMenu(string username, int id) { Console.WriteLine("[1] Item toevoegen"); Console.WriteLine("[2] Item verwijderen"); - Console.WriteLine("[3] Item aanpassen"); + // Console.WriteLine("[3] Item aanpassen"); Console.WriteLine("[T] Terug"); string input = Console.ReadLine(); @@ -17,12 +17,12 @@ public static void EditMenu(string username, int id) case "2": RemoveItem(username, id); break; - case "3": - Console.WriteLine("Functie momenteel buiten werking"); - Console.ReadKey(); - ManagerMenu.Admin_menu(username, id);// zodat je terug gaat - // ChangeItem(username, id); - break; + // case "3": + // Console.WriteLine("Functie momenteel buiten werking"); + // Console.ReadKey(); + // ManagerMenu.Admin_menu(username, id);// zodat je terug gaat + // // ChangeItem(username, id); + // break; case "T": ManagerMenu.Admin_menu(username, id);// zodat je terug gaat break; diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index f97308b..26a795e 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -42,7 +42,7 @@ public void Reserveren() string phoneCheck; string phonePattern = @"^(?:\+31|0)6\d{8}$"; - + do { Console.WriteLine("(Optioneel) Wat is uw telefoon nummer? (+31612345678 or 0612345678)"); @@ -186,8 +186,8 @@ public void Reserveren() { ReservationLogic.AddReservation(id, 0, name, email, date, reservationcode, timeslot, tables, amt_people); Console.WriteLine("Gelukt!"); - Email.sendmail(email, name, reservationcode, date, timeslot); - Email.warning(); + EmailFunction.sendmail(email, name, reservationcode, date, timeslot); + EmailFunction.warning(); } catch { @@ -330,8 +330,8 @@ public void Reserveren(int client_id, string username) { ReservationLogic.AddReservation(id, clientnumber, name, email, date, reservationcode, timeslot, tables, amt_people); Console.WriteLine("Geluk!"); - Email.sendmail(email, name, reservationcode, date, timeslot); - Email.warning(); + EmailFunction.sendmail(email, name, reservationcode, date, timeslot); + EmailFunction.warning(); } catch (Exception e) { diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 2fd323d..c210ef6 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -2,10 +2,12 @@ using Project_B.Logic; using Project_B.DataModels; -public class Reservation { +public class Reservation +{ static private AccountsLogic accountsLogic = new AccountsLogic(); - static public void DisplayReservation() { + static public void DisplayReservation() + { List reservations = ReservationLogic.GetReservations(); Console.ForegroundColor = ConsoleColor.DarkGreen; @@ -13,18 +15,21 @@ static public void DisplayReservation() { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("--------------------"); Console.WriteLine("{0,-5} {1,-30} {2,-15} {3,-15} {4,-15} {5,-10}", "ID", "Naam", "Datum", "Tijd", "Tafel nummers", "Aantal Pers."); - + Console.ForegroundColor = ConsoleColor.DarkGreen; - foreach (ReservationModel reservation in reservations) { + foreach (ReservationModel reservation in reservations) + { Console.WriteLine("{0,-5} {1,-30} {2,-15} {3,-15} {4,-15} {5,-10}", reservation.ID, reservation.Name, reservation.Date.ToString("dd-MM-yyyy"), reservation.TimeSlot.ToString(@"hh\:mm"), string.Join(", ", reservation.Tables), reservation.Amt_People); } Console.ForegroundColor = ConsoleColor.Gray; } - static public void MakeReservation() { + static public void MakeReservation() + { string HasAccount; - do { + do + { Console.Write("Heeft de klant een account? (J/N): "); HasAccount = Console.ReadLine().ToUpper(); } while (HasAccount != "J" && HasAccount != "N"); @@ -34,56 +39,67 @@ static public void MakeReservation() { string Email = ""; - if (HasAccount == "J") { + if (HasAccount == "J") + { string SearchTerm; - do { + do + { Console.Write("Zoeken naar account (Email): "); SearchTerm = Console.ReadLine().ToLower(); } while (SearchTerm.Length == 0); - try { + try + { AccountModel AccountData = accountsLogic.GetByEmail(SearchTerm); - + ClientNumber = Convert.ToString(AccountData.Id); Name = AccountData.FullName; Email = AccountData.EmailAddress; - } catch (Exception e) { + } + catch (Exception e) + { Console.WriteLine("Account niet gevonden!"); HasAccount = "N"; } - + } - if (HasAccount == "N") { - do { + if (HasAccount == "N") + { + do + { Console.Write("Naam: "); Name = Console.ReadLine(); } while (Name.Length <= 3); - - do { + + do + { Console.Write("Email: "); Email = Console.ReadLine(); } while (ValidationLogic.IsValidEmail(Email) != true); } string Date; - do { + do + { Console.Write("Date (DD-MM-JJJJ): "); Date = Console.ReadLine(); } while (ValidationLogic.IsValidDate(Date) != true); string TimeSlot; - do { + do + { Console.Write("Time (00:00): "); TimeSlot = Console.ReadLine(); } while (ValidationLogic.IsValidTime(TimeSlot) != true); int Amt_People; - do { + do + { Console.Write("Aantal Personen: "); Amt_People = Convert.ToInt32(Console.ReadLine()); } while (Amt_People <= 0); @@ -93,18 +109,25 @@ static public void MakeReservation() { Console.WriteLine($"Tafelnummers beschikbaar: " + string.Join(", ", AvailableTables)); Console.WriteLine("Tafel nummers (klaar ENTER)"); - List Tables = new List (); - while (true) { + List Tables = new List(); + while (true) + { string Table_number = Console.ReadLine(); // Keep looping until user pressed ENTER, only numeric - if (Table_number != "") { - try { + if (Table_number != "") + { + try + { Tables.Add(Table_number); - } catch { + } + catch + { Console.WriteLine("Toevoegen mislukt, voer tafel nummers in!"); } - } else { + } + else + { break; } @@ -115,60 +138,78 @@ static public void MakeReservation() { bool ChangedValue = ReservationLogic.AddReservation((ReservationLogic.GetLastID() + 1), Convert.ToInt32(ClientNumber), Name, Email, DateTime.Parse(Date), ReservationLogic.CodeGenerator(), TimeSpan.Parse(TimeSlot), Tables, Convert.ToInt32(Amt_People)); // Reservation returns a boolean of the process - if (ChangedValue != true) { + if (ChangedValue != true) + { Console.WriteLine("Er is iets fouts gegaan!"); - } else { + } + else + { Console.WriteLine("Gelukt!"); + EmailFunction.sendmail(Email, Name, ReservationLogic.CodeGenerator(), DateTime.Parse(Date), TimeSpan.Parse(TimeSlot)); } } - static public void ChangeReservation() { + static public void ChangeReservation() + { Console.Write("Zoeken (ID / Naam / Email): "); string Searchterm = Console.ReadLine(); - if (ReservationLogic.GetReservation(Searchterm) != null) { + if (ReservationLogic.GetReservation(Searchterm) != null) + { string Name; - do { + do + { Console.Write("Naam: "); Name = Console.ReadLine(); } while (Name.Length <= 3); - + string Email; - do { + do + { Console.Write("Email: "); Email = Console.ReadLine(); } while (ValidationLogic.IsValidEmail(Email) != true); string Date; - do { + do + { Console.Write("Date (DD-MM-JJJJ): "); Date = Console.ReadLine(); } while (ValidationLogic.IsValidDate(Date) != true); string TimeSlot; - do { + do + { Console.Write("Time (00:00): "); TimeSlot = Console.ReadLine(); } while (ValidationLogic.IsValidTime(TimeSlot) != true); string Amt_People; - do { + do + { Console.Write("Aantal Personen: "); Amt_People = Console.ReadLine(); } while (ValidationLogic.IsNumeric(Amt_People) != true); - Console.WriteLine("Beschikbare tafels: " + string.Join(", " ,TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Convert.ToInt32(Amt_People)))); + Console.WriteLine("Beschikbare tafels: " + string.Join(", ", TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Convert.ToInt32(Amt_People)))); Console.WriteLine("Tafel nummers"); - List Tables = new List (); - while (true) { + List Tables = new List(); + while (true) + { string Table_number = Console.ReadLine(); - if (Table_number != "") { - try { + if (Table_number != "") + { + try + { Tables.Add(Table_number); - } catch { + } + catch + { Console.WriteLine("Toevoegen mislukt, voer tafel nummers in!"); } - } else { + } + else + { break; } @@ -177,24 +218,30 @@ static public void ChangeReservation() { // All values has been checked and ready to be changed bool ChangedValue = ReservationLogic.ChangeReservation(Searchterm, Name, Email, DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Tables, Convert.ToInt32(Amt_People)); - if (ChangedValue != true) { + if (ChangedValue != true) + { Console.WriteLine("Er is iets fouts gegaan!"); - } else { + } + else + { Console.WriteLine("Gelukt!"); } - } - else { + } + else + { Console.WriteLine("Niet gevonden"); } } - public static void DeleteReservationWithID() { + public static void DeleteReservationWithID() + { Console.WriteLine("ID"); int ID = Convert.ToInt32(Console.ReadLine()); ReservationModel ReservationObject = ReservationLogic.GetReservation(Convert.ToString(ID)); - if (ReservationObject == null) { + if (ReservationObject == null) + { Console.WriteLine("Reservatie niet gevonden!"); return; } @@ -202,29 +249,35 @@ public static void DeleteReservationWithID() { Console.WriteLine($"\nID: {ReservationObject.ID}"); Console.WriteLine($"Name: {ReservationObject.Name}"); Console.WriteLine($"Email: {ReservationObject.Email}"); - Console.WriteLine($"\nWeet u zeker dat deze reservering wordt verwijderd?"); + Console.WriteLine($"\nWeet u zeker dat deze reservering wordt verwijderd?"); - string DeleteObjectbool = ""; - do { + string DeleteObjectbool = ""; + do + { Console.WriteLine($"(J/N)"); DeleteObjectbool = Console.ReadLine().ToUpper(); } while (DeleteObjectbool != "J" && DeleteObjectbool != "N"); - if (DeleteObjectbool == "J") { + if (DeleteObjectbool == "J") + { bool DeletedObject = ReservationLogic.DeleteReservation(ID); - if (DeletedObject != true) { + if (DeletedObject != true) + { Console.WriteLine("Er is iets fouts gegaan!"); - } - else { + } + else + { Console.WriteLine("Gelukt!"); } - } else if (DeleteObjectbool == "N") { + } + else if (DeleteObjectbool == "N") + { Console.WriteLine("Geannuleerd."); } - - + + } } \ No newline at end of file From 83d024b539875b9852184cbf1e8c4de5c87b4591 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Mon, 5 Jun 2023 09:16:37 +0200 Subject: [PATCH 16/63] Gangen menu kan je goed lezen en prijs aanpassen --- DataModels/FoodModel.cs | 2 + DataSources/menu.json | 107 +++++++++++++++++++++++++++++++++++++++- Logic/FoodMenu.cs | 12 +++++ Logic/Food_Aanpassen.cs | 66 ++++++++++++++++++++++++- Presentation/Show.cs | 52 +++++++++++++------ 5 files changed, 223 insertions(+), 16 deletions(-) diff --git a/DataModels/FoodModel.cs b/DataModels/FoodModel.cs index fc452d5..33004b3 100644 --- a/DataModels/FoodModel.cs +++ b/DataModels/FoodModel.cs @@ -15,6 +15,7 @@ public class Foodmenu public List Desserts { get; set; } public List Drinks { get; set; } public List Wijn { get; set; } + public List Gangen { get; set; } public Foodmenu() { Starters = new List(); @@ -23,6 +24,7 @@ public Foodmenu() Desserts = new List(); Drinks = new List(); Wijn = new List(); + Gangen = new List(); } } \ No newline at end of file diff --git a/DataSources/menu.json b/DataSources/menu.json index 56826de..3f271c4 100644 --- a/DataSources/menu.json +++ b/DataSources/menu.json @@ -1 +1,106 @@ -{"Starters":[{"ID":1,"Category":null,"Name":"Caesar Salad","Price":8.0},{"ID":2,"Category":null,"Name":"Garlic Bread","Price":4.99}],"Soups":[{"ID":1,"Category":null,"Name":"Tomaten soep","Price":12.50}],"Mains":[{"ID":1,"Category":null,"Name":"Spaghetti Bolognese","Price":12.99},{"ID":2,"Category":null,"Name":"Beef Burger","Price":10.99}],"Desserts":[{"ID":1,"Category":null,"Name":"Cheesecake","Price":5.99},{"ID":2,"Category":null,"Name":"Chocolate Brownie","Price":4.99},{"ID":3,"Category":null,"Name":"appeltaart","Price":4.5}],"Drinks":[{"ID":1,"Category":null,"Name":"Coca-Cola","Price":2.49},{"ID":2,"Category":null,"Name":"Orange juice","Price":2.5}],"Wijn":[{"ID":3,"Category":null,"Name":"Vodka","Price":13.5},{"ID":4,"Category":null,"Name":"Barcardi","Price":4.5}]} \ No newline at end of file +{ + "Starters": [ + { + "ID": 1, + "Category": null, + "Name": "Caesar Salad", + "Price": 8.0 + }, + { + "ID": 2, + "Category": null, + "Name": "Garlic Bread", + "Price": 4.99 + } + ], + "Soups": [ + { + "ID": 1, + "Category": null, + "Name": "Tomaten soep", + "Price": 12.5 + } + ], + "Mains": [ + { + "ID": 1, + "Category": null, + "Name": "Spaghetti Bolognese", + "Price": 12.99 + }, + { + "ID": 2, + "Category": null, + "Name": "Beef Burger", + "Price": 10.99 + } + ], + "Desserts": [ + { + "ID": 1, + "Category": null, + "Name": "Cheesecake", + "Price": 5.99 + }, + { + "ID": 2, + "Category": null, + "Name": "Chocolate Brownie", + "Price": 4.99 + }, + { + "ID": 3, + "Category": null, + "Name": "appeltaart", + "Price": 4.5 + } + ], + "Drinks": [ + { + "ID": 1, + "Category": null, + "Name": "Coca-Cola", + "Price": 2.49 + }, + { + "ID": 2, + "Category": null, + "Name": "Orange juice", + "Price": 2.5 + } + ], + "Wijn": [ + { + "ID": 3, + "Category": null, + "Name": "Vodka", + "Price": 13.5 + }, + { + "ID": 4, + "Category": null, + "Name": "Barcardi", + "Price": 4.5 + } + ], + "Gangen": [ + { + "ID": 1, + "Category": null, + "Name": "2 Gangen menu", + "Price": 15.5 + }, + { + "ID": 2, + "Category": null, + "Name": "3 Gangen menu", + "Price": 20.50 + }, + { + "ID": 3, + "Category": null, + "Name": "4 Gangen menu", + "Price": 25.5 + } + ] +} \ No newline at end of file diff --git a/Logic/FoodMenu.cs b/Logic/FoodMenu.cs index fa31bf5..99a7714 100644 --- a/Logic/FoodMenu.cs +++ b/Logic/FoodMenu.cs @@ -58,6 +58,10 @@ public static Foodmenu ImportFromJson(string filename) { menu.Soups.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); } + foreach (var item in data.Gangen) + { + menu.Gangen.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } return menu; } public static void AddMenuItem(Foodmenu menu, MenuItem item, string filename) @@ -95,6 +99,11 @@ public static void AddMenuItem(Foodmenu menu, MenuItem item, string filename) item.Category = null; // set the category property to null menu.Wijn.Add(item); break; + case "Gangen": + item.ID = menu.Gangen.Count > 0 ? menu.Gangen.Max(i => i.ID) + 1 : 1; + item.Category = null; // set the category property to null + menu.Gangen.Add(item); + break; default: throw new Exception("Invalid category specified"); } @@ -127,6 +136,9 @@ public static void RemoveItem(Foodmenu menu, string category, int id, string fil case "Soups": itemList = menu.Wijn; break; + case "Gangen": + itemList = menu.Gangen; + break; default: throw new Exception("Invalid category specified"); } diff --git a/Logic/Food_Aanpassen.cs b/Logic/Food_Aanpassen.cs index f044e7e..420fe4d 100644 --- a/Logic/Food_Aanpassen.cs +++ b/Logic/Food_Aanpassen.cs @@ -5,7 +5,7 @@ public static void EditMenu(string username, int id) { Console.WriteLine("[1] Item toevoegen"); Console.WriteLine("[2] Item verwijderen"); - // Console.WriteLine("[3] Item aanpassen"); + Console.WriteLine("[3] Gangen menu prijs aanpassen"); Console.WriteLine("[T] Terug"); string input = Console.ReadLine(); @@ -17,6 +17,9 @@ public static void EditMenu(string username, int id) case "2": RemoveItem(username, id); break; + case "3": + ChangePrice(username, id); + break; // case "3": // Console.WriteLine("Functie momenteel buiten werking"); // Console.ReadKey(); @@ -178,6 +181,67 @@ public static void RemoveItem(string username, int user_id) Console.WriteLine($"Item {itemToRemove.Name} met ID {itemToRemove.ID} is succesvol verwijderd uit de categorie {category}."); ManagerMenu.Admin_menu(username, user_id);// zodat je terug gaat } + + // make method that makes sure that u can edit an "gangen menu's" price + public static void ChangePrice(string username, int user_id) + { + // get the menu stuff + string filenaam = @"DataSources/menu.json"; + Foodmenu menu = MenuImporter.ImportFromJson(filenaam); + + // let the admin choose what menu price he wants to change + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "2 Gangen menu", "3 Gangen menu", "4 Gangen menu"); + MenuItem GangenMenu = null; + switch (selectedClass) + { + case 0: + // it's the 2 gangen menu + GangenMenu = GetGangenMenu(1, menu.Gangen); + break; + case 1: + // it's the 3 gangen menu + GangenMenu = GetGangenMenu(2, menu.Gangen); + break; + case 2: + // it's the 4 gangen menu + GangenMenu = GetGangenMenu(3, menu.Gangen); + break; + } + + // check if the menu item is found + if (GangenMenu != null) + { + // get the new price from the admin + Console.WriteLine($"Vul de nieuwe prijs voor {GangenMenu}:"); + decimal newPrice = Convert.ToDecimal(Console.ReadLine()); + + // update the price of the menu item + GangenMenu.Price = newPrice; + + // save the updated menu to the JSON file + MenuImporter.SaveMenuToJson(menu, filenaam); + + Console.WriteLine($"De prijs van {GangenMenu.Name} is veranderd naar: {GangenMenu.Price}."); + } + else + { + Console.WriteLine("Er gaat iets fout!."); + } + + ManagerMenu.Admin_menu(username, user_id); // return to the admin menu + } + + private static MenuItem GetGangenMenu(int id, List items) + { + foreach (MenuItem item in items) + { + if (item.ID == id) + { + return item; + } + } + return null; + } // na vragen bij PO of item aanpas wel moest, zo ja pas hem ook aan voor wijn // public static void ChangeItem(string username, int user_id) // { diff --git a/Presentation/Show.cs b/Presentation/Show.cs index f09535f..283610b 100644 --- a/Presentation/Show.cs +++ b/Presentation/Show.cs @@ -5,18 +5,13 @@ public class MenuPresentation public static void Menu() { Foodmenu menu = MenuImporter.ImportFromJson(@"DataSources/menu.json"); - Console.WriteLine("╔════════════════════════════════════════╗"); - Console.WriteLine("║ Restaurant Menu ║"); - Console.WriteLine("╚════════════════════════════════════════╝"); - Console.WriteLine("2 Gangen menu ......1x Hoofdgerecht en 1x Nagerecht .................................15,50"); - Console.WriteLine("3 Ganger menu ......1x Voorgerecht, 1x Hoofdgerecht en 1x Nagerecht .................20,50"); - Console.WriteLine("4 Ganger menu ......1x Voorgerecht, 1x Soep 1x Hoofdgerecht, 1x Nagerecht ...........25,50"); - // maak functie om te kiezen welke menu de klant wilt int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "2 Gangen menu", "3 Gangen menu", "4 Gangen menu"); switch (selectedClass) { case 0: + // print the information + informatie(menu.Gangen); // 2 gangen menu Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, includePrice: true); @@ -31,6 +26,8 @@ public static void Menu() DisplayMenuItems(menu.Drinks, includePrice: true); break; case 1: + // print the information + informatie(menu.Gangen); // 3 gangen menu Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, includePrice: true); @@ -48,6 +45,8 @@ public static void Menu() DisplayMenuItems(menu.Drinks, includePrice: true); break; default: + // print the information + informatie(menu.Gangen); // 4 gangen menu Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, includePrice: true); @@ -74,18 +73,13 @@ public static void Menu() public static void Menu(string username, int id) { Foodmenu menu = MenuImporter.ImportFromJson(@"DataSources/menu.json"); - Console.WriteLine("╔════════════════════════════════════════╗"); - Console.WriteLine("║ Restaurant Menu ║"); - Console.WriteLine("╚════════════════════════════════════════╝"); - Console.WriteLine("2 Gangen menu ......1x Hoofdgerecht en 1x Nagerecht .................................15,50"); - Console.WriteLine("3 Ganger menu ......1x Voorgerecht, 1x Hoofdgerecht en 1x Nagerecht .................20,50"); - Console.WriteLine("4 Ganger menu ......1x Voorgerecht, 1x Soep 1x Hoofdgerecht, 1x Nagerecht ...........25,50"); - // maak functie om te kiezen welke menu de klant wilt int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "2 Gangen menu", "3 Gangen menu", "4 Gangen menu"); switch (selectedClass) { case 0: + // print the information + informatie(menu.Gangen); // 2 gangen menu Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, username, id, includePrice: true); @@ -100,6 +94,8 @@ public static void Menu(string username, int id) DisplayMenuItems(menu.Drinks, username, id, includePrice: true); break; case 1: + // print the information + informatie(menu.Gangen); // 3 gangen menu Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, username, id, includePrice: true); @@ -117,6 +113,8 @@ public static void Menu(string username, int id) DisplayMenuItems(menu.Drinks, username, id, includePrice: true); break; default: + // print the information + informatie(menu.Gangen); // 4 gangen menu Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, username, id, includePrice: true); @@ -140,6 +138,27 @@ public static void Menu(string username, int id) Console.ReadKey(); } + private static void informatie(List items) + { + Console.WriteLine("╔════════════════════════════════════════╗"); + Console.WriteLine("║ Restaurant Menu ║"); + Console.WriteLine("╚════════════════════════════════════════╝"); + foreach (MenuItem menu in items) + { + if (menu.Name == "2 Gangen menu") + { + Console.WriteLine($"{menu.Name}: 1x voorgerecht en 1x hoofdgerecht".PadRight(80, '.') + " " + menu.Price.ToString("F2")); + } + else if (menu.Name == "3 Gangen menu") + { + Console.WriteLine($"{menu.Name}: 1x voorgerecht, 1x hoofdgerecht en 1x nagerecht".PadRight(80, '.') + " " + menu.Price.ToString("F2")); + } + else if (menu.Name == "4 Gangen menu") + { + Console.WriteLine($"{menu.Name}: 1x voorgerecht, 1x soep, 1x hoofdgerecht en 1x nagerecht".PadRight(80, '.') + " " + menu.Price.ToString("F2")); + } + } + } private static void DisplayMenuItems(List items, bool includePrice) { foreach (MenuItem item in items) @@ -168,6 +187,11 @@ private static void DisplayMenuItems(List items, string naam, int id, } } } + // // mehtod return's Gangen menu in list + // private static List GetGangenMenu(List items, bool includePrice) + // { + + // } } public class LocationPresentation From 3bb4d162e4ceb074bfe4866585cd64923ded0613 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Mon, 5 Jun 2023 09:29:01 +0200 Subject: [PATCH 17/63] Manager gefinetuned --- Presentation/ManagerMenu.cs | 40 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/Presentation/ManagerMenu.cs b/Presentation/ManagerMenu.cs index 42a3054..b5442a9 100644 --- a/Presentation/ManagerMenu.cs +++ b/Presentation/ManagerMenu.cs @@ -4,13 +4,15 @@ public class ManagerMenu static public void Admin_menu(string username, int id) { - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] {}, "Menu", "Reserveringen ", "Medewerkers", "Log uit"); + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "Menu", "Reserveringen ", "Medewerkers", "Restaurant informatie", "Log uit"); - switch (selectedClass) { + switch (selectedClass) + { case 0: - selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {}, "Menu aanpassen", "Menu bekijken", "Terug"); + selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Menu aanpassen", "Menu bekijken", "Terug"); - switch (selectedClass) { + switch (selectedClass) + { case 0: MenuAanpassen.EditMenu(username, id); break; @@ -23,15 +25,15 @@ static public void Admin_menu(string username, int id) break; } break; - + case 1: - selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {}, "Reservering bekijken", "Reservering maken", "Reservering aanpassen", "Reservering verwijderen", "Terug"); + selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Reservering bekijken", "Reservering maken", "Reservering aanpassen", "Reservering verwijderen", "Terug"); - switch (selectedClass) { + switch (selectedClass) + { case 0: Console.Clear(); Reservation.DisplayReservation(); - Console.WriteLine("Druk op iets om verder te gaan..."); Console.ReadKey(); Admin_menu(username, id); @@ -58,11 +60,12 @@ static public void Admin_menu(string username, int id) break; } break; - + case 2: - selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {}, "Medewerkers toevoegen", "Terug"); + selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Medewerkers toevoegen", "Terug"); - switch (selectedClass) { + switch (selectedClass) + { case 0: Mederwerker.Toevoeg_Mederwerker_Menu(username, id); break; @@ -71,6 +74,21 @@ static public void Admin_menu(string username, int id) break; } break; + case 3: + // start de locatie class en show detail + Location location = Location.CreateLocation(); + LocationPresentation.ShowLocation(location); + Console.ReadKey(); + Admin_menu(username, id); + break; + case 4: + // uitloggen + Menu.Start(); + break; + default: + // iets ging fout + Admin_menu(username, id); + break; } } } \ No newline at end of file From 37420e6632446b3cf27992286179117e78650b0a Mon Sep 17 00:00:00 2001 From: Henno85657 <85657@glr.nl> Date: Mon, 5 Jun 2023 12:08:05 +0200 Subject: [PATCH 18/63] Added a function which reserv you want to choose --- Logic/ReservationLogic.cs | 4 ---- Presentation/Reservation/ReservationView.cs | 14 +++++++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index d7a3947..cedeae7 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -80,8 +80,6 @@ public static List GetReservations(string _Searchterm) { //Get reservations from other function List reservations = GetReservations(); - // List UpdatableFields = new() {"name", "email", "date", "timeslot", "tables", "amt_people"}; - //Loop through the list and get the reservation by the given searchterm foreach (ReservationModel reservation in reservations) { if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) { @@ -104,8 +102,6 @@ public static ReservationModel GetReservation(string _Searchterm) { //Get reservations from other function List reservations = GetReservations(); - // List UpdatableFields = new() {"name", "email", "date", "timeslot", "tables", "amt_people"}; - //Loop through the list and get the reservation by the given searchterm foreach (ReservationModel reservation in reservations) { if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) { diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index c210ef6..5a20329 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -154,8 +154,16 @@ static public void ChangeReservation() Console.Write("Zoeken (ID / Naam / Email): "); string Searchterm = Console.ReadLine(); - if (ReservationLogic.GetReservation(Searchterm) != null) - { + List r = ReservationLogic.GetReservations(Searchterm); + + if (r != null) { + if (r.Count() > 1) { + foreach (ReservationModel reservation in r) { + Console.WriteLine($"[{reservation.ID}] {reservation.Email} - {reservation.TimeSlot}"); + } + Searchterm = Console.ReadLine(); + } + string Name; do { @@ -191,7 +199,7 @@ static public void ChangeReservation() Amt_People = Console.ReadLine(); } while (ValidationLogic.IsNumeric(Amt_People) != true); - Console.WriteLine("Beschikbare tafels: " + string.Join(", ", TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Convert.ToInt32(Amt_People)))); + Console.WriteLine("Beschikbare tafels: " + string.Join(", ", TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Convert.ToInt32(Amt_People)).Select(x => x.Substring(1)).ToList())); Console.WriteLine("Tafel nummers"); List Tables = new List(); while (true) From ddd0a4a21b7d64380badc99e38fe27e820979ff5 Mon Sep 17 00:00:00 2001 From: joelhogeschool <124694056+joelhogeschool@users.noreply.github.com> Date: Mon, 5 Jun 2023 21:50:35 +0200 Subject: [PATCH 19/63] workermenu the beginning of workermenu --- Presentation/AccountData.cs | 55 +++++++++++++++++++++++++++++++++++++ Presentation/Menu.cs | 6 ++++ Presentation/UserLogin.cs | 4 +++ Presentation/WorkerMenu.cs | 42 ++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 Presentation/WorkerMenu.cs diff --git a/Presentation/AccountData.cs b/Presentation/AccountData.cs index c5c72bf..2ea7d4d 100644 --- a/Presentation/AccountData.cs +++ b/Presentation/AccountData.cs @@ -88,4 +88,59 @@ static public void Start(int id) // ingelogd geef parameter's mee om aan te geve } } + + static public void StartWorker(int id) // ingelogd geef parameter's mee om aan te geven dat de persoon is ingelogd + { + AccountModel acc = accountsLogic.GetById(id); + + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {}, $"Email: {acc.EmailAddress}", $"Wachtwoord: {acc.Password}", $"Volledige naam: {acc.FullName}", "Terug"); + if (selectedClass == 0) + { + // check syntax email, Will return an error message if not correct or the email already exists. + do + { + Console.WriteLine("Vul hier uw nieuwe email."); + acc.EmailAddress = Console.ReadLine().ToLower(); + } while (ValidationLogic.IsValidEmail(acc.EmailAddress) != true && accountsLogic.CheckRegistration(acc.EmailAddress) != null); + + // updates email to json and returns to StartWorker + accountsLogic.UpdateList(acc); + StartWorker(id); + } + else if (selectedClass == 1) + { + do{ + Console.WriteLine("Graag hier je wachtwoord invullen:"); + Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter en 1 cijfer"); + acc.Password = Console.ReadLine(); + } while (ValidationLogic.IsValidPassword(acc.Password) != true); + + // updates password to json and returns to StartWorker + accountsLogic.UpdateList(acc); + StartWorker(id); + } + else if (selectedClass == 2) + { + do + { + Console.WriteLine("Graag hier je volledige naam invullen:"); + acc.FullName = Console.ReadLine().ToLower(); + if (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")) + { + Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); + } + } while (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")); + + // updates full name to json and returns to StartWorker + accountsLogic.UpdateList(acc); + StartWorker(id); + } + + else if (selectedClass == 3) + { + // je wordt terug gestuurd naar de CustomerMenu + WorkerMenu.Start(acc.FullName, id); + } + + } } \ No newline at end of file diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index 99d5fe8..4aecd78 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -66,4 +66,10 @@ static public void Admin(int id, string username) Console.WriteLine($"Welkom admin : {username}"); ManagerMenu.Admin_menu(username, id); } + // medewerker gedeelte ------------------------------------------------------------------------- medewerker gedeelte + static public void Worker(int id, string username) + { + Console.WriteLine($"Welkom Worker: {username}"); + WorkerMenu.Start(username, id); + } } \ No newline at end of file diff --git a/Presentation/UserLogin.cs b/Presentation/UserLogin.cs index b812f1b..a320eea 100644 --- a/Presentation/UserLogin.cs +++ b/Presentation/UserLogin.cs @@ -50,6 +50,10 @@ public static void Start() { Menu.Admin(id, naam); } + else if (level == 1) // aka het is een medewerker + { + Menu.Worker(id, naam); + } } else { diff --git a/Presentation/WorkerMenu.cs b/Presentation/WorkerMenu.cs new file mode 100644 index 0000000..1c6dcc3 --- /dev/null +++ b/Presentation/WorkerMenu.cs @@ -0,0 +1,42 @@ +using Project_B.Logic; + +class WorkerMenu +{ + static public void Start(string username, int id) // ingelogd geef parameter's mee om aan te geven dat de persoon is ingelogd + { + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Menu bekijken", "Reserveren voor klant", "Restaurant informatie", "Mijn gegevens", "Log uit"); + if (selectedClass == 0) + { + // voor stellen om een foto te laten up poppen van een menu kaart, anders vraag wat precies geshowed moet worden + MenuPresentation.Menu(); + Console.ReadKey(); + Start(username, id); + } + else if (selectedClass == 1) + { + // ga naar reserveren waar je een paar optie's weer krijgt + // Reservatie res = new Reservatie(); + ReservationConsole res = new ReservationConsole(); + res.Reserveren(id, username); + } + else if (selectedClass == 2) + { + // start de locatie class en show detail + Location location = Location.CreateLocation(); + LocationPresentation.ShowLocation(location); + Start(username, id); + } + else if (selectedClass == 3) + { + AccountData.StartWorker(id); + } + + else if (selectedClass == 4) + { + // roep welkom aan sinds je word uitgelogd + Welkom.welkom(); + // je word gestuurd naar start aka je bent uitgelogd' + Menu.Start(); + } + } +} \ No newline at end of file From a52449d4dfb15266192a6583a81b5bcf3d49981b Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 6 Jun 2023 10:49:03 +0200 Subject: [PATCH 20/63] inheritance geadd --- DataModels/Customer.cs | 8 +++ DataModels/Employee.cs | 8 +++ DataModels/Manager.cs | 8 +++ Presentation/Menu.cs | 24 +++++--- Presentation/UserLogin.cs | 115 +++++++++++++++++++++----------------- 5 files changed, 102 insertions(+), 61 deletions(-) create mode 100644 DataModels/Customer.cs create mode 100644 DataModels/Employee.cs create mode 100644 DataModels/Manager.cs diff --git a/DataModels/Customer.cs b/DataModels/Customer.cs new file mode 100644 index 0000000..3d31769 --- /dev/null +++ b/DataModels/Customer.cs @@ -0,0 +1,8 @@ +class Customer : AccountModel +{ + public Customer(int id, string emailAddress, string password, string fullName, int level) + : base(id, emailAddress, password, fullName, level) + { + // Additional customer-specific properties and logic can be added here + } +} diff --git a/DataModels/Employee.cs b/DataModels/Employee.cs new file mode 100644 index 0000000..bb5de03 --- /dev/null +++ b/DataModels/Employee.cs @@ -0,0 +1,8 @@ +class Employee : AccountModel +{ + public Employee(int id, string emailAddress, string password, string fullName, int level) + : base(id, emailAddress, password, fullName, level) + { + // Additional employee-specific properties and logic can be added here + } +} diff --git a/DataModels/Manager.cs b/DataModels/Manager.cs new file mode 100644 index 0000000..35f7f9b --- /dev/null +++ b/DataModels/Manager.cs @@ -0,0 +1,8 @@ +class Manager : AccountModel +{ + public Manager(int id, string emailAddress, string password, string fullName, int level) + : base(id, emailAddress, password, fullName, level) + { + // Additional manager-specific properties and logic can be added here + } +} \ No newline at end of file diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index 99d5fe8..676f1d8 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -54,16 +54,22 @@ static public void Start() } } - static public void Continue(int id, string username) + static public void Continue(AccountModel persoon) { // je bent ingelogd - Console.WriteLine($"Welkom {username}, je id is: {id}"); - CustomerMenu.Start(username, id); - } - // admin gedeelte ------------------------------------------------------------------------- admin gedeelte - static public void Admin(int id, string username) - { - Console.WriteLine($"Welkom admin : {username}"); - ManagerMenu.Admin_menu(username, id); + if (persoon is Manager) + { + // ga naar managers menu + ManagerMenu.Admin_menu(persoon.FullName, persoon.Id); + } + else if (persoon is Employee) + { + // ga naarmederwerkers menu + } + else if (persoon is Customer) + { + // ga naar customers menu + CustomerMenu.Start(persoon.FullName, persoon.Id); + } } } \ No newline at end of file diff --git a/Presentation/UserLogin.cs b/Presentation/UserLogin.cs index b812f1b..4f75dc5 100644 --- a/Presentation/UserLogin.cs +++ b/Presentation/UserLogin.cs @@ -2,62 +2,73 @@ namespace Project_B.Logic; static class UserLogin { - static private AccountsLogic accountsLogic = new AccountsLogic(); + static private AccountsLogic accountsLogic = new AccountsLogic(); - public static void Start() - { - string email = ""; - string password = ""; - Console.Clear(); - - bool accountNull = true; - while (accountNull is true) + public static void Start() { - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, $"Email: {email}", $"Wachtwoord: {new string('*', password.Length)}", "", "Login", "Annuleren"); - if (selectedClass == 0) - { - Console.WriteLine("Graag uw email invullen."); - email = Console.ReadLine(); - } - else if (selectedClass == 1) - { - Console.WriteLine("Graag uw wachtwoord invullen."); - password = Console.ReadLine(); - } - else if (selectedClass == 4) - { - Menu.Start(); - } - else if (selectedClass == 3) - { - accountNull = false; - AccountModel acc = accountsLogic.CheckLogin(email, password); - if (acc != null) - { - //Console.WriteLine("Welcome back " + acc.FullName); - //Console.WriteLine("Your email number is " + acc.EmailAddress); - int id = acc.Id; - string naam = acc.FullName; - int level = acc.Level; - //Write some code to go back to the menu - // ingelogd versie - if (level == 0) // wanneer het een gewone gast is - { - Menu.Continue(id, naam); - } - else if (level == 1) // aka het is een admin - { - Menu.Admin(id, naam); - } - } - else + string email = ""; + string password = ""; + Console.Clear(); + + bool accountNull = true; + while (accountNull is true) { - Console.WriteLine("No account found with that email and password"); - System.Threading.Thread.Sleep(1000); - Start(); + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, $"Email: {email}", $"Wachtwoord: {new string('*', password.Length)}", "", "Login", "Annuleren"); + if (selectedClass == 0) + { + Console.WriteLine("Graag uw email invullen."); + email = Console.ReadLine(); + } + else if (selectedClass == 1) + { + Console.WriteLine("Graag uw wachtwoord invullen."); + password = Console.ReadLine(); + } + else if (selectedClass == 4) + { + Menu.Start(); + } + else if (selectedClass == 3) + { + accountNull = false; + AccountModel acc = accountsLogic.CheckLogin(email, password); + if (acc != null) + { + //Console.WriteLine("Welcome back " + acc.FullName); + //Console.WriteLine("Your email number is " + acc.EmailAddress); + int id = acc.Id; + string naam = acc.FullName; + int level = acc.Level; + string mail = acc.EmailAddress; + string ww = acc.Password; + + AccountModel persoon = null; + // op basis van level geef de user zn eigen model + if (level == 1) // Manager + { + persoon = new Manager(id, mail, ww, naam, level); + // Additional manager-specific logic here + } + else if (level == 2) // Employee + { + persoon = new Employee(id, mail, ww, naam, level); + // Additional employee-specific logic here + } + else if (level == 0) // Customer + { + persoon = new Customer(id, mail, ww, naam, level); + // Additional customer-specific logic here + } + Menu.Continue(persoon); + } + else + { + Console.WriteLine("No account found with that email and password"); + System.Threading.Thread.Sleep(1000); + Start(); + } + } } - } } - } } \ No newline at end of file From 2cb393cb807eecae7b8911968f098bbc6783ff2e Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 6 Jun 2023 12:42:25 +0200 Subject: [PATCH 21/63] Prijs voor de berekeningen word uit json gepakt --- Logic/Prijs.cs | 43 ++++++++++++++----- .../Reservation/ReservationConsole.cs | 4 +- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Logic/Prijs.cs b/Logic/Prijs.cs index ef3c74a..1fc6fa9 100644 --- a/Logic/Prijs.cs +++ b/Logic/Prijs.cs @@ -1,16 +1,37 @@ public class Prijs { + // get the price's // Fields for the gangen menu prices - public double gangenmenu_2 = 15.50; - public double gangenmenu_3 = 20.50; - public double gangenmenu_4 = 25.50; + public decimal gangenmenu_2; + public decimal gangenmenu_3; + public decimal gangenmenu_4; + + public Prijs() + { + Foodmenu menu = MenuImporter.ImportFromJson(@"DataSources/menu.json"); + foreach (MenuItem x in menu.Gangen) + { + if (x.Name == "2 Gangen menu") + { + gangenmenu_2 = x.Price; + } + else if (x.Name == "3 Gangen menu") + { + gangenmenu_3 = x.Price; + } + else if (x.Name == "4 Gangen menu") + { + gangenmenu_4 = x.Price; + } + } + } // Field for the discount percentage - public double discount = 0.1; - public double wijn_arrangement = 3.50; + public decimal discount = 0.1M; + public decimal wijn_arrangement = 3.50M; // Method to calculate the price - public double prijs(int aantal) + public decimal prijs(int aantal) { // Prompt for the chosen gangen menu Console.WriteLine("Welke gangen menu gaat u nemen?"); @@ -62,7 +83,7 @@ public double prijs(int aantal) // ... } } - double menuPrijs = 0.0; + decimal menuPrijs = 0; // Calculate the price based on the chosen menu switch (menu) @@ -78,20 +99,20 @@ public double prijs(int aantal) break; default: Console.WriteLine("Ongeldige menukeuze."); - return 0.0; // Return 0 if an invalid menu choice is entered + return 0.0M; // Return 0 if an invalid menu choice is entered } // Calculate the total price - double totPrijs = menuPrijs * aantal; + decimal totPrijs = menuPrijs * aantal; // Apply the discount for people under 12 - double korting = menuPrijs * onder_12 * discount; + decimal korting = menuPrijs * onder_12 * discount; totPrijs -= korting; // zorg nu dat je de wijn erbij doet if (wineCount > 0) { // indien er dus wel mensen zijn met wijn - double wijnprijs = wijn_arrangement * wineCount; + decimal wijnprijs = wijn_arrangement * wineCount; totPrijs += wijnprijs; } return totPrijs; diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 26a795e..5c02847 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -102,7 +102,7 @@ public void Reserveren() // je weet nu hoeveel mensen er zullen komen voeg (maruf) functie's toe om te weten hoeveel het zal kosten Prijs geld = new Prijs(); - double money = geld.prijs(amt_people); + decimal money = geld.prijs(amt_people); Console.WriteLine($"\nIn totaal betaal je voor {amt_people} mensen {money} euro."); Console.WriteLine("Druk op iets om verder te gaan..."); @@ -247,7 +247,7 @@ public void Reserveren(int client_id, string username) // je weet nu hoeveel mensen er zullen komen voeg (maruf) functie's toe om te weten hoeveel het zal kosten Prijs geld = new Prijs(); - double money = geld.prijs(amt_people); + decimal money = geld.prijs(amt_people); Console.WriteLine($"intotaal betaal je voor {amt_people} mensen {money:f2} euro."); Console.WriteLine("Druk op iets om verder te gaan..."); Console.ReadKey(); From 4ec6f0437c85c8b61d17474506997b9e69a10635 Mon Sep 17 00:00:00 2001 From: Henno0701 <1048091@hr.nl> Date: Tue, 6 Jun 2023 16:03:37 +0200 Subject: [PATCH 22/63] GetReservations() bug fix --- DataModels/ReservationModel.cs | 2 +- DataSources/reservations.json | 15 +++++++++++++++ Logic/ReservationLogic.cs | 16 ++++++---------- Presentation/Reservation/ReservationView.cs | 14 +++++++++++++- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/DataModels/ReservationModel.cs b/DataModels/ReservationModel.cs index 4519c20..3167b36 100644 --- a/DataModels/ReservationModel.cs +++ b/DataModels/ReservationModel.cs @@ -36,7 +36,7 @@ public class ReservationModel public int Amt_People {get; set;} [JsonPropertyName("Course_Menu")] - public int CourseMenu {get; set;} + public int? CourseMenu {get; set;} [JsonPropertyName("Verified")] public bool Verified {get; set;} diff --git a/DataSources/reservations.json b/DataSources/reservations.json index d2e8779..841c84c 100644 --- a/DataSources/reservations.json +++ b/DataSources/reservations.json @@ -28,5 +28,20 @@ "Amt_People": 4, "CourseMenu": null, "Verified": false + }, + { + "ID": 3, + "ClientNumber": 0, + "Name": "test", + "Email": "test@gmail.com", + "Date": "2023-06-07T00:00:00", + "ReservationCode": "ED3R7X", + "TimeSlot": "20:00:00", + "Tables": [ + "1" + ], + "Amt_People": 2, + "CourseMenu": null, + "Verified": false } ] \ No newline at end of file diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index d7a3947..86e3b30 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -51,7 +51,7 @@ public static bool AddReservation(int _id, int _clientnumber, string _name, stri //Serialize the list to an object and write it back to the JSON file. Return true when all went good string updatedJson = JsonConvert.SerializeObject(reservations, Formatting.Indented); - File.WriteAllText("DataSources/reservations.json", updatedJson); + File.WriteAllText(@"DataSources/reservations.json", updatedJson); return true; } catch (Exception ex) { // Catch the error and return false @@ -62,14 +62,14 @@ public static bool AddReservation(int _id, int _clientnumber, string _name, stri public static List GetReservations() { try { //Try to get the reservations and convert them into a list - string jsonContent = File.ReadAllText("DataSources/reservations.json"); + string jsonContent = File.ReadAllText(@"DataSources/reservations.json"); List reservations = JsonConvert.DeserializeObject>(jsonContent); - return reservations != null ? reservations : new List(); + return reservations.Count > 0 ? reservations : new List(); } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + // Console.WriteLine($"Error: {ex.Message}"); } return new List(); } @@ -80,8 +80,6 @@ public static List GetReservations(string _Searchterm) { //Get reservations from other function List reservations = GetReservations(); - // List UpdatableFields = new() {"name", "email", "date", "timeslot", "tables", "amt_people"}; - //Loop through the list and get the reservation by the given searchterm foreach (ReservationModel reservation in reservations) { if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) { @@ -104,8 +102,6 @@ public static ReservationModel GetReservation(string _Searchterm) { //Get reservations from other function List reservations = GetReservations(); - // List UpdatableFields = new() {"name", "email", "date", "timeslot", "tables", "amt_people"}; - //Loop through the list and get the reservation by the given searchterm foreach (ReservationModel reservation in reservations) { if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) { @@ -140,7 +136,7 @@ public static bool ChangeReservation(string _Searchterm, string _name, string _e //Serialize the list and write it back to JSON file string updatedJson = JsonConvert.SerializeObject(reservations, Formatting.Indented); - File.WriteAllText("DataSources/reservations.json", updatedJson); + File.WriteAllText(@"DataSources/reservations.json", updatedJson); return true; } catch (Exception ex) @@ -161,7 +157,7 @@ public static bool DeleteReservation(int _ID) reservations.RemoveAll(x => x.ID == _ID); string updatedJson = JsonConvert.SerializeObject(reservations, Formatting.Indented); - File.WriteAllText("DataSources/reservations.json", updatedJson); + File.WriteAllText(@"DataSources/reservations.json", updatedJson); return true; } diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index c210ef6..fbf2b4a 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -154,8 +154,20 @@ static public void ChangeReservation() Console.Write("Zoeken (ID / Naam / Email): "); string Searchterm = Console.ReadLine(); - if (ReservationLogic.GetReservation(Searchterm) != null) + List r = ReservationLogic.GetReservations(Searchterm); + + if (r != null) { + if (r.Count > 1) { + string[] r_choices = new string[] {}; + foreach (ReservationModel reservation in r) { + // r_choices.Add($"{reservation.ID}"); + } + + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, r_choices); + + } + string Name; do { From a17a028d17a2ed455a7f07c27a3f76951c99b97b Mon Sep 17 00:00:00 2001 From: Henno85657 <85657@glr.nl> Date: Tue, 6 Jun 2023 23:48:01 +0200 Subject: [PATCH 23/63] ChangeReservation() Style update --- DataModels/ReservationModel.cs | 5 ++++ Logic/ReservationLogic.cs | 2 +- Presentation/Reservation/ReservationView.cs | 30 ++++++++++----------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/DataModels/ReservationModel.cs b/DataModels/ReservationModel.cs index 3167b36..17e2320 100644 --- a/DataModels/ReservationModel.cs +++ b/DataModels/ReservationModel.cs @@ -53,6 +53,11 @@ public ReservationModel(int _id, int _clientnumber, string _name, string _email, Amt_People = _amt_people; Verified = false; } + + public override string ToString() + { + return $"{Email} - {Date.ToString("dd-MM-yyyy")} ({TimeSlot.ToString(@"hh\:mm")})"; + } } diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index 86e3b30..c3027da 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -82,7 +82,7 @@ public static List GetReservations(string _Searchterm) { //Loop through the list and get the reservation by the given searchterm foreach (ReservationModel reservation in reservations) { - if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) { + if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm || reservation.ReservationCode == _Searchterm) { ResList.Add(reservation); //Return the reservation } } diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 8c62700..4f51711 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -151,28 +151,26 @@ static public void MakeReservation() static public void ChangeReservation() { - Console.Write("Zoeken (ID / Naam / Email): "); + Console.Write("Zoeken (ID / Naam / Email / Reservering Code): "); string Searchterm = Console.ReadLine(); List r = ReservationLogic.GetReservations(Searchterm); - // if (r != null) - // { - // if (r.Count > 1) { - // string[] r_choices = new string[] {}; - // foreach (ReservationModel reservation in r) { - // // r_choices.Add($"{reservation.ID}"); - // } - - // int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, r_choices); - - if (r != null) { - if (r.Count() > 1) { + if (r != null) + { + if (r.Count > 1) { + List r_choices = new List {}; foreach (ReservationModel reservation in r) { - Console.WriteLine($"[{reservation.ID}] {reservation.Email} - {reservation.TimeSlot}"); + r_choices.Add($"[{reservation.ID}] {reservation.ToString()}"); } - Searchterm = Console.ReadLine(); - } + + string[] Array_r_choices = r_choices.ToArray(); + + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {$"Er zijn meerdere reserveringen gevonden met de zoekterm: {Searchterm}", "Kies de juiste reservering"}, Array_r_choices); + + Searchterm = Array_r_choices[selectedClass].Split("]")[0].Remove(0, 1); + + } string Name; do From f28e2b8eb45012b676cc4c29a940ea0c9f364a95 Mon Sep 17 00:00:00 2001 From: Henno85657 <85657@glr.nl> Date: Wed, 7 Jun 2023 00:19:21 +0200 Subject: [PATCH 24/63] MyReservation() get correct reservation fix --- Logic/ReservationLogic.cs | 21 ++++++++++++++++++ Presentation/Reservation/MyReservation.cs | 26 +++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index c3027da..9ffb0df 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -95,6 +95,27 @@ public static List GetReservations(string _Searchterm) { return new List(); } + public static List GetReservations(int clientnumber) { + List ResList = new(); + try { + //Get reservations from other function + List reservations = GetReservations(); + + //Loop through the list and get the reservation by the given searchterm + foreach (ReservationModel reservation in reservations) { + if (reservation.ClientNumber == clientnumber) { + ResList.Add(reservation); //Return the reservation + } + } + return ResList; //Return nothing if nothing came out + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + return new List(); + } + public static ReservationModel GetReservation(string _Searchterm) { try { //Try to get the reservation and convert them into a list diff --git a/Presentation/Reservation/MyReservation.cs b/Presentation/Reservation/MyReservation.cs index b5a2c59..7d1814c 100644 --- a/Presentation/Reservation/MyReservation.cs +++ b/Presentation/Reservation/MyReservation.cs @@ -20,17 +20,35 @@ public static string GetReservationCode() { public static string GetReservationCode(string username, int id) { try { //Try to find the reservation code by the id of the user. When it does not excist it will return a empty string - List reservations = ReservationLogic.GetReservations(); - string ReservationCode = reservations.Find(x => x.ID == id).ReservationCode; + List reservations = ReservationLogic.GetReservations(id); + string ReservationCode; + if (reservations.Count > 1) { + List r_choices = new List {}; + foreach (ReservationModel reservation in reservations) { + r_choices.Add($"[{reservation.ID}] {reservation.ToString()}"); + } + + string[] Array_r_choices = r_choices.ToArray(); + + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {$"Er zijn meerdere reserveringen gevonden onder uw naam", "Kies de juiste reservering"}, Array_r_choices); + + int r_id = Convert.ToInt32(Array_r_choices[selectedClass].Split("]")[0].Remove(0, 1)); + Console.WriteLine(r_id); + ReservationCode = reservations.Find(x => x.ID == r_id).ReservationCode; + } else { + ReservationCode = reservations.Find(x => x.ClientNumber == id).ReservationCode; + } + Console.WriteLine(ReservationCode); return ReservationCode; - } catch { + } catch (Exception e) { + Console.WriteLine(e); return ""; } } - static public void ShowReservationInfo( string _ReservationCode) { + static public void ShowReservationInfo(string _ReservationCode) { List reservations = ReservationLogic.GetReservations(); From 838bb0145ea2febaf34dd81ccd36d7e91e308819 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Wed, 7 Jun 2023 13:57:09 +0200 Subject: [PATCH 25/63] locatie gegevens zijn niet hard dated --- DataModels/Location.cs | 38 ++++++++++ DataSources/Informatie.json | 16 ++++ Logic/InformatieLogic.cs | 103 +++++++++++++++++++++++++ Logic/Location.cs | 31 -------- Logic/ReservationLogic.cs | 146 +++++++++++++++++++++--------------- Presentation/ManagerMenu.cs | 23 ++++-- 6 files changed, 259 insertions(+), 98 deletions(-) create mode 100644 DataModels/Location.cs create mode 100644 DataSources/Informatie.json create mode 100644 Logic/InformatieLogic.cs delete mode 100644 Logic/Location.cs diff --git a/DataModels/Location.cs b/DataModels/Location.cs new file mode 100644 index 0000000..db6f734 --- /dev/null +++ b/DataModels/Location.cs @@ -0,0 +1,38 @@ +using System.Text.Json; +public class Location +{ + public string Name { get; set; } + public string Address { get; set; } + public string Phone { get; set; } + public string Email { get; set; } + public string Website { get; set; } + public Dictionary OpeningHours { get; set; } + + public Location(string name, string address, string phone, string email, Dictionary openingHours) + { + Name = name; + Address = address; + Phone = phone; + Email = email; + OpeningHours = openingHours; + } + + public static Location CreateLocation() + { + string json = File.ReadAllText(@"DataSources/Informatie.json"); + Location location = JsonSerializer.Deserialize(json); + + return location; + } + + public void SaveToJsonFile(string filePath) + { + string json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); + File.WriteAllText(filePath, json); + } + public static Location ReadLocationFromJson(string filePath) + { + string json = File.ReadAllText(filePath); + return JsonSerializer.Deserialize(json); + } +} \ No newline at end of file diff --git a/DataSources/Informatie.json b/DataSources/Informatie.json new file mode 100644 index 0000000..616ebf2 --- /dev/null +++ b/DataSources/Informatie.json @@ -0,0 +1,16 @@ +{ + "Name": "Jake\u0027s restaurant", + "Address": "Wijnhaven 107", + "Phone": "0695684596", + "Email": "JakeRestaurant@gmail.com", + "Website": null, + "OpeningHours": { + "zondag": "18:00-22:00", + "maandag": "18:00-22:00", + "dinsdag": "18:00-22:00", + "woensdag": "18:00-22:00", + "donderdag": "18:00-22:00", + "vrijdag": "18:00-22:00", + "zaterdag": "18:00-22:00" + } +} \ No newline at end of file diff --git a/Logic/InformatieLogic.cs b/Logic/InformatieLogic.cs new file mode 100644 index 0000000..b6aa9a1 --- /dev/null +++ b/Logic/InformatieLogic.cs @@ -0,0 +1,103 @@ +namespace Project_B.Logic; +using System.Text; +public class RestaurantInformatie +{ + public static void UpdateLocation(string username, int id) + { + Location location = Location.CreateLocation(); + + bool isModified = false; // Flag to track if any changes were made + bool menu = true; + do + { + int selectedOption = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, + "Save Changes", + "Annuleren", + $"Name: {location.Name}", + $"Address: {location.Address}", + $"Phone: {location.Phone}", + $"Email: {location.Email}", + $"Opening Hours: \n{GetFormattedOpeningHours(location.OpeningHours)}"); + + switch (selectedOption) + { + case 0: + // Save Changes + if (isModified) + { + // Save the updated location to a JSON file + location.SaveToJsonFile(@"DataSources/Informatie.json"); + // ga terug naar admin menu + menu = false; + } + else + { + Console.WriteLine("No changes were made. Nothing to save."); + // ga terug naar admin menu + menu = false; + } + break; + case 1: + // Annuleren + // ga terug naar admin menu + menu = false; + break; + case 2: + // Name + Console.Write("Enter the new name: "); + string newName = Console.ReadLine(); + location.Name = newName; + isModified = true; + break; + case 3: + // Address + Console.Write("Enter the new address: "); + string newAddress = Console.ReadLine(); + location.Address = newAddress; + isModified = true; + break; + case 4: + // Phone + Console.Write("Enter the new phone number: "); + string newPhone = Console.ReadLine(); + location.Phone = newPhone; + isModified = true; + break; + case 5: + // Email + Console.Write("Enter the new email address: "); + string newEmail = Console.ReadLine(); + location.Email = newEmail; + isModified = true; + break; + case 6: + // Opening Hours + Dictionary newOpeningHours = new Dictionary(); + foreach (var day in location.OpeningHours.Keys) + { + Console.Write($"Enter the new opening hours for {day}: "); + string newHours = Console.ReadLine(); + newOpeningHours.Add(day, newHours); + } + location.OpeningHours = newOpeningHours; + isModified = true; + break; + } + } while (menu); + // Return to the admin menu\ + ManagerMenu.Admin_menu(username, id);// zodat je terug gaat + } + + // Helper method to format the opening hours dictionary + private static string GetFormattedOpeningHours(Dictionary openingHours) + { + StringBuilder sb = new StringBuilder(); + + foreach (var kvp in openingHours) + { + sb.AppendLine($"{kvp.Key}: {kvp.Value}"); + } + + return sb.ToString(); + } +} diff --git a/Logic/Location.cs b/Logic/Location.cs deleted file mode 100644 index cac375c..0000000 --- a/Logic/Location.cs +++ /dev/null @@ -1,31 +0,0 @@ -public class Location -{ - public string Name { get; set; } - public string Address { get; set; } - public string Phone { get; set; } - public string Email { get; set; } - public string Website { get; set; } - public Dictionary OpeningHours { get; set; } - - public Location(string name, string address, string phone, string email, Dictionary openingHours) - { - Name = name; - Address = address; - Phone = phone; - Email = email; - OpeningHours = openingHours; - } - public static Location CreateLocation() // maak de locatie aan - { - return new Location("Restaurant XYZ", "Main Street 123", "123456789", "info@restaurantxyz.com", new Dictionary - { - { "zondag", "12:00–17:00" }, - { "maandag", "12:00–18:00" }, - { "dinsdag", "10:00–18:00" }, - { "woensdag", "10:00–18:00" }, - { "donderdag", "10:00–20:00" }, - { "vrijdag", "10:00–18:00" }, - { "zaterdag", "10:00–18:00" } - }); - } -} diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index cedeae7..1e8e526 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -11,38 +11,40 @@ namespace Project_B.Logic { public static class ReservationLogic { - static string unavailable = "\u001b[31m"; - static string available = "\u001b[32m"; - static string cyan = "\u001b[36m"; - - public static List availableTables = new List(); - - static string _6A = unavailable; - static string _6B = unavailable; - static string _4A = unavailable; - static string _4B = unavailable; - static string _4C = unavailable; - static string _4D = unavailable; - static string _4E = unavailable; - static string _1 = unavailable; - static string _2 = unavailable; - static string _3 = unavailable; - static string _4 = unavailable; - static string _5 = unavailable; - static string _6 = unavailable; - static string _7 = unavailable; - static string _8 = unavailable; - static string A = unavailable; - static string B = unavailable; - static string C = unavailable; - static string D = unavailable; - static string E = unavailable; - static string F = unavailable; - static string G = unavailable; - static string H = unavailable; - - public static bool AddReservation(int _id, int _clientnumber, string _name, string _email, DateTime _date, string _reservationcode, TimeSpan _timeslot, List _tables, int _amt_people) { - try { + static string unavailable = "\u001b[31m"; + static string available = "\u001b[32m"; + static string cyan = "\u001b[36m"; + + public static List availableTables = new List(); + + static string _6A = unavailable; + static string _6B = unavailable; + static string _4A = unavailable; + static string _4B = unavailable; + static string _4C = unavailable; + static string _4D = unavailable; + static string _4E = unavailable; + static string _1 = unavailable; + static string _2 = unavailable; + static string _3 = unavailable; + static string _4 = unavailable; + static string _5 = unavailable; + static string _6 = unavailable; + static string _7 = unavailable; + static string _8 = unavailable; + static string A = unavailable; + static string B = unavailable; + static string C = unavailable; + static string D = unavailable; + static string E = unavailable; + static string F = unavailable; + static string G = unavailable; + static string H = unavailable; + + public static bool AddReservation(int _id, int _clientnumber, string _name, string _email, DateTime _date, string _reservationcode, TimeSpan _timeslot, List _tables, int _amt_people) + { + try + { //Get reservations from other function List reservations = GetReservations(); @@ -54,13 +56,16 @@ public static bool AddReservation(int _id, int _clientnumber, string _name, stri File.WriteAllText("DataSources/reservations.json", updatedJson); return true; } - catch (Exception ex) { // Catch the error and return false + catch (Exception ex) + { // Catch the error and return false return false; } } - - public static List GetReservations() { - try { + + public static List GetReservations() + { + try + { //Try to get the reservations and convert them into a list string jsonContent = File.ReadAllText("DataSources/reservations.json"); List reservations = JsonConvert.DeserializeObject>(jsonContent); @@ -74,17 +79,21 @@ public static List GetReservations() { return new List(); } - public static List GetReservations(string _Searchterm) { + public static List GetReservations(string _Searchterm) + { List ResList = new(); - try { + try + { //Get reservations from other function List reservations = GetReservations(); //Loop through the list and get the reservation by the given searchterm - foreach (ReservationModel reservation in reservations) { - if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) { + foreach (ReservationModel reservation in reservations) + { + if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) + { ResList.Add(reservation); //Return the reservation - } + } } return ResList; //Return nothing if nothing came out } @@ -95,18 +104,22 @@ public static List GetReservations(string _Searchterm) { return new List(); } - public static ReservationModel GetReservation(string _Searchterm) { - try { + public static ReservationModel GetReservation(string _Searchterm) + { + try + { //Try to get the reservation and convert them into a list //Get reservations from other function List reservations = GetReservations(); //Loop through the list and get the reservation by the given searchterm - foreach (ReservationModel reservation in reservations) { - if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) { + foreach (ReservationModel reservation in reservations) + { + if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) + { return reservation; //Return the reservation - } + } } return null; //Return nothing if nothing came out } @@ -116,14 +129,18 @@ public static ReservationModel GetReservation(string _Searchterm) { } } - public static bool ChangeReservation(string _Searchterm, string _name, string _email, DateTime _date, TimeSpan _timeslot, List _tables, int _amt_people) { - try { + public static bool ChangeReservation(string _Searchterm, string _name, string _email, DateTime _date, TimeSpan _timeslot, List _tables, int _amt_people) + { + try + { //Get reservations from other function List reservations = GetReservations(); //Loop through the list and get the reservation by the given searchterm - foreach (ReservationModel reservation in reservations) { - if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) { + foreach (ReservationModel reservation in reservations) + { + if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm) + { //Change the old value to the new value reservation.Name = _name; reservation.Email = _email; @@ -149,7 +166,8 @@ public static bool ChangeReservation(string _Searchterm, string _name, string _e public static bool DeleteReservation(int _ID) { //Todo: Add a parameter to GetReservation called ID. ID will also return a Object. - try { + try + { //Get reservations from other function List reservations = GetReservations(); @@ -168,8 +186,10 @@ public static bool DeleteReservation(int _ID) } } - public static bool VerifyingReservation(int _ID) { - try { + public static bool VerifyingReservation(int _ID) + { + try + { //Get reservations from other function List reservations = GetReservations(); @@ -179,15 +199,16 @@ public static bool VerifyingReservation(int _ID) { //Send data back to JSON file string updatedJson = JsonConvert.SerializeObject(reservations, Formatting.Indented); File.WriteAllText("DataSources/reservations.json", updatedJson); - + return true; - } - catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); return false; } } - + public static void UpdateTableAvailability(List TablesList) { _6A = TablesList.Contains("_6A") ? available : unavailable; @@ -276,18 +297,19 @@ public static void ShowTables() public static int GetLastID() { - List> ids = new (); + List> ids = new(); //Get reservations from other function List reservations = GetReservations(); - foreach (ReservationModel reservation in reservations) { + foreach (ReservationModel reservation in reservations) + { ids.Add(Tuple.Create(reservation.ID)); } - + return reservations.Count() != 0 ? ids.Max(x => x.Item1) : 0; } - + public static string CodeGenerator() { //Creating object of random class diff --git a/Presentation/ManagerMenu.cs b/Presentation/ManagerMenu.cs index b5442a9..3fff501 100644 --- a/Presentation/ManagerMenu.cs +++ b/Presentation/ManagerMenu.cs @@ -75,11 +75,24 @@ static public void Admin_menu(string username, int id) } break; case 3: - // start de locatie class en show detail - Location location = Location.CreateLocation(); - LocationPresentation.ShowLocation(location); - Console.ReadKey(); - Admin_menu(username, id); + selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Locatie bekijken", "Locatie aanpassen", "Terug"); + + switch (selectedClass) + { + case 0: + // start de locatie class en show detail + Location location = Location.CreateLocation(); + LocationPresentation.ShowLocation(location); + Console.ReadKey(); + Admin_menu(username, id); + break; + case 1: + RestaurantInformatie.UpdateLocation(username, id); + break; + case 2: + Admin_menu(username, id); + break; + } break; case 4: // uitloggen From 9976f9174f13ac270d9510efa45802b83d76f562 Mon Sep 17 00:00:00 2001 From: Henno85657 <85657@glr.nl> Date: Wed, 7 Jun 2023 15:24:28 +0200 Subject: [PATCH 26/63] push --- DataSources/reservations.json | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/DataSources/reservations.json b/DataSources/reservations.json index 841c84c..2e36b37 100644 --- a/DataSources/reservations.json +++ b/DataSources/reservations.json @@ -1,7 +1,7 @@ [ { "ID": 1, - "ClientNumber": 0, + "ClientNumber": 9, "Name": "Henno Passchier", "Email": "henno.passchier@gmail.com", "Date": "2023-05-26T00:00:00", @@ -28,20 +28,5 @@ "Amt_People": 4, "CourseMenu": null, "Verified": false - }, - { - "ID": 3, - "ClientNumber": 0, - "Name": "test", - "Email": "test@gmail.com", - "Date": "2023-06-07T00:00:00", - "ReservationCode": "ED3R7X", - "TimeSlot": "20:00:00", - "Tables": [ - "1" - ], - "Amt_People": 2, - "CourseMenu": null, - "Verified": false } ] \ No newline at end of file From eafd4f1c2afe0b0f18cb0f53fc353f2d0269f9b8 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Wed, 7 Jun 2023 17:56:29 +0200 Subject: [PATCH 27/63] info tijden nettjes onder elkaar --- Logic/InformatieLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Logic/InformatieLogic.cs b/Logic/InformatieLogic.cs index b6aa9a1..8137b16 100644 --- a/Logic/InformatieLogic.cs +++ b/Logic/InformatieLogic.cs @@ -95,7 +95,7 @@ private static string GetFormattedOpeningHours(Dictionary openin foreach (var kvp in openingHours) { - sb.AppendLine($"{kvp.Key}: {kvp.Value}"); + sb.AppendLine($" {kvp.Key}: {kvp.Value}"); } return sb.ToString(); From bfa46f82bf6e711bff8271ffad5afc84d1c77601 Mon Sep 17 00:00:00 2001 From: joelhogeschool <124694056+joelhogeschool@users.noreply.github.com> Date: Wed, 7 Jun 2023 20:59:42 +0200 Subject: [PATCH 28/63] finished workermenu --- DataSources/reservations.json | 15 ++++++++++ Presentation/AccountData.cs | 55 ----------------------------------- Presentation/Menu.cs | 1 + Presentation/WorkerMenu.cs | 11 +++---- 4 files changed, 20 insertions(+), 62 deletions(-) diff --git a/DataSources/reservations.json b/DataSources/reservations.json index 2e36b37..c6ab7ec 100644 --- a/DataSources/reservations.json +++ b/DataSources/reservations.json @@ -28,5 +28,20 @@ "Amt_People": 4, "CourseMenu": null, "Verified": false + }, + { + "ID": 3, + "ClientNumber": 0, + "Name": "test test", + "Email": "test@test.nl", + "Date": "2023-06-07T00:00:00", + "ReservationCode": "GK2U8E", + "TimeSlot": "16:00:00", + "Tables": [ + "1" + ], + "Amt_People": 2, + "CourseMenu": null, + "Verified": false } ] \ No newline at end of file diff --git a/Presentation/AccountData.cs b/Presentation/AccountData.cs index 2ea7d4d..a7be266 100644 --- a/Presentation/AccountData.cs +++ b/Presentation/AccountData.cs @@ -86,61 +86,6 @@ static public void Start(int id) // ingelogd geef parameter's mee om aan te geve // je wordt terug gestuurd naar de CustomerMenu CustomerMenu.Start(acc.FullName, id); } - } - static public void StartWorker(int id) // ingelogd geef parameter's mee om aan te geven dat de persoon is ingelogd - { - AccountModel acc = accountsLogic.GetById(id); - - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {}, $"Email: {acc.EmailAddress}", $"Wachtwoord: {acc.Password}", $"Volledige naam: {acc.FullName}", "Terug"); - if (selectedClass == 0) - { - // check syntax email, Will return an error message if not correct or the email already exists. - do - { - Console.WriteLine("Vul hier uw nieuwe email."); - acc.EmailAddress = Console.ReadLine().ToLower(); - } while (ValidationLogic.IsValidEmail(acc.EmailAddress) != true && accountsLogic.CheckRegistration(acc.EmailAddress) != null); - - // updates email to json and returns to StartWorker - accountsLogic.UpdateList(acc); - StartWorker(id); - } - else if (selectedClass == 1) - { - do{ - Console.WriteLine("Graag hier je wachtwoord invullen:"); - Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter en 1 cijfer"); - acc.Password = Console.ReadLine(); - } while (ValidationLogic.IsValidPassword(acc.Password) != true); - - // updates password to json and returns to StartWorker - accountsLogic.UpdateList(acc); - StartWorker(id); - } - else if (selectedClass == 2) - { - do - { - Console.WriteLine("Graag hier je volledige naam invullen:"); - acc.FullName = Console.ReadLine().ToLower(); - if (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")) - { - Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); - } - } while (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")); - - // updates full name to json and returns to StartWorker - accountsLogic.UpdateList(acc); - StartWorker(id); - } - - else if (selectedClass == 3) - { - // je wordt terug gestuurd naar de CustomerMenu - WorkerMenu.Start(acc.FullName, id); - } - - } } \ No newline at end of file diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index 73abfdd..a74b7df 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -65,6 +65,7 @@ static public void Continue(AccountModel persoon) else if (persoon is Employee) { // ga naarmederwerkers menu + WorkerMenu.Start(persoon.FullName, persoon.Id); } else if (persoon is Customer) { diff --git a/Presentation/WorkerMenu.cs b/Presentation/WorkerMenu.cs index 1c6dcc3..b5d4740 100644 --- a/Presentation/WorkerMenu.cs +++ b/Presentation/WorkerMenu.cs @@ -4,7 +4,7 @@ class WorkerMenu { static public void Start(string username, int id) // ingelogd geef parameter's mee om aan te geven dat de persoon is ingelogd { - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Menu bekijken", "Reserveren voor klant", "Restaurant informatie", "Mijn gegevens", "Log uit"); + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Menu bekijken", "Reserveren voor klant", "Restaurant informatie", "Log uit"); if (selectedClass == 0) { // voor stellen om een foto te laten up poppen van een menu kaart, anders vraag wat precies geshowed moet worden @@ -17,21 +17,18 @@ static public void Start(string username, int id) // ingelogd geef parameter's m // ga naar reserveren waar je een paar optie's weer krijgt // Reservatie res = new Reservatie(); ReservationConsole res = new ReservationConsole(); - res.Reserveren(id, username); + res.Reserveren(); + Start(username, id); } else if (selectedClass == 2) { // start de locatie class en show detail Location location = Location.CreateLocation(); LocationPresentation.ShowLocation(location); + Console.ReadKey(); Start(username, id); } else if (selectedClass == 3) - { - AccountData.StartWorker(id); - } - - else if (selectedClass == 4) { // roep welkom aan sinds je word uitgelogd Welkom.welkom(); From 8000ead316ab26e9b4a2518ba4f5d51f0bbd5f7f Mon Sep 17 00:00:00 2001 From: maruf128 Date: Thu, 8 Jun 2023 08:37:32 +0200 Subject: [PATCH 29/63] ervoor gezorgd dat de wijn prijs niet harddated is --- DataSources/menu.json | 8 +++++++- Logic/Food_Aanpassen.cs | 6 +++++- Logic/Prijs.cs | 14 ++++++++++---- Presentation/Show.cs | 4 ++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/DataSources/menu.json b/DataSources/menu.json index 3f271c4..458a531 100644 --- a/DataSources/menu.json +++ b/DataSources/menu.json @@ -94,13 +94,19 @@ "ID": 2, "Category": null, "Name": "3 Gangen menu", - "Price": 20.50 + "Price": 20.5 }, { "ID": 3, "Category": null, "Name": "4 Gangen menu", "Price": 25.5 + }, + { + "ID": 4, + "Category": null, + "Name": "Wijn arrangement", + "Price": 4.50 } ] } \ No newline at end of file diff --git a/Logic/Food_Aanpassen.cs b/Logic/Food_Aanpassen.cs index 420fe4d..fedd076 100644 --- a/Logic/Food_Aanpassen.cs +++ b/Logic/Food_Aanpassen.cs @@ -190,7 +190,7 @@ public static void ChangePrice(string username, int user_id) Foodmenu menu = MenuImporter.ImportFromJson(filenaam); // let the admin choose what menu price he wants to change - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "2 Gangen menu", "3 Gangen menu", "4 Gangen menu"); + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "2 Gangen menu", "3 Gangen menu", "4 Gangen menu", "Wijn arrangement"); MenuItem GangenMenu = null; switch (selectedClass) { @@ -206,6 +206,10 @@ public static void ChangePrice(string username, int user_id) // it's the 4 gangen menu GangenMenu = GetGangenMenu(3, menu.Gangen); break; + case 3: + // het is de wijn arrangement + GangenMenu = GetGangenMenu(4, menu.Gangen); + break; } // check if the menu item is found diff --git a/Logic/Prijs.cs b/Logic/Prijs.cs index 1fc6fa9..588e603 100644 --- a/Logic/Prijs.cs +++ b/Logic/Prijs.cs @@ -5,7 +5,7 @@ public class Prijs public decimal gangenmenu_2; public decimal gangenmenu_3; public decimal gangenmenu_4; - + public decimal wijn_arrangement; public Prijs() { Foodmenu menu = MenuImporter.ImportFromJson(@"DataSources/menu.json"); @@ -23,12 +23,15 @@ public Prijs() { gangenmenu_4 = x.Price; } + else if (x.Name == "Wijn arrangement") + { + wijn_arrangement = x.Price; + } } } // Field for the discount percentage public decimal discount = 0.1M; - public decimal wijn_arrangement = 3.50M; // Method to calculate the price public decimal prijs(int aantal) @@ -59,10 +62,13 @@ public decimal prijs(int aantal) while (!validInput) { Console.WriteLine($"Hoeveel van de {aantal} personen zijn 12 jaar of jonger?"); - onder_12 = Convert.ToInt32(Console.ReadLine()); + string inputOnder12 = Console.ReadLine(); + onder_12 = string.IsNullOrEmpty(inputOnder12) ? 0 : Convert.ToInt32(inputOnder12); Console.WriteLine($"Hoeveel van de {aantal} personen willen het wijnarrangement ({wijn_arrangement})?"); - wineCount = Convert.ToInt32(Console.ReadLine()); + string inputWineCount = Console.ReadLine(); + wineCount = string.IsNullOrEmpty(inputWineCount) ? 0 : Convert.ToInt32(inputWineCount); + if (onder_12 > aantal) { diff --git a/Presentation/Show.cs b/Presentation/Show.cs index 283610b..5e8763a 100644 --- a/Presentation/Show.cs +++ b/Presentation/Show.cs @@ -157,6 +157,10 @@ private static void informatie(List items) { Console.WriteLine($"{menu.Name}: 1x voorgerecht, 1x soep, 1x hoofdgerecht en 1x nagerecht".PadRight(80, '.') + " " + menu.Price.ToString("F2")); } + else if (menu.Name == "Wijn arrangement") + { + Console.WriteLine($"{menu.Name} kost {menu.Price.ToString("F2")}"); + } } } private static void DisplayMenuItems(List items, bool includePrice) From 4e8cecdea9ad5c0a8d6135d96bcbcd00012abd2d Mon Sep 17 00:00:00 2001 From: maruf128 Date: Thu, 8 Jun 2023 11:00:35 +0200 Subject: [PATCH 30/63] table changes --- Logic/TableLogic.cs | 59 ++++++++++++------- .../Reservation/ReservationConsole.cs | 50 ++++++++++++---- Presentation/Reservation/ReservationView.cs | 18 +++--- 3 files changed, 87 insertions(+), 40 deletions(-) diff --git a/Logic/TableLogic.cs b/Logic/TableLogic.cs index ac0f231..03637f9 100644 --- a/Logic/TableLogic.cs +++ b/Logic/TableLogic.cs @@ -11,34 +11,47 @@ namespace Project_B.Logic public static class TableLogic { - public static List AvailableTables = new List {"_6A", "_6B", "_4A", "_4B", "_4C", "_4D", "_4E", "_1", "_2", "_3", "_4", "_5", "_6", "_7", "_8", "A", "B", "C", "D", "E", "F", "G", "H" }; + public static List AvailableTables = new List { "6A", "6B", "4A", "4B", "4C", "4D", "4E", "1", "2", "3", "4", "5", "6", "7", "8", "A", "B", "C", "D", "E", "F", "G", "H" }; - public static List CheckTables(DateTime date, TimeSpan timeslot, int persons) { + public static List CheckTables(DateTime date, TimeSpan timeslot, int persons) + { List res = ReservationLogic.GetReservations(); //Get the reservations in an object and loop throught it - if (res != null) { - foreach (ReservationModel reservartion in res) { - if (reservartion.Date == date && reservartion.TimeSlot == timeslot) { //Only select the reservation that are given by Date/Time - if(reservartion.Tables != null) { //Check if the reservation has tablenumbers in it - foreach (string i in reservartion.Tables) { - AvailableTables.Remove($"_{i}"); //Remove the tablenumber from the available table list + if (res != null) + { + foreach (ReservationModel reservartion in res) + { + if (reservartion.Date == date && reservartion.TimeSlot == timeslot) + { //Only select the reservation that are given by Date/Time + if (reservartion.Tables != null) + { //Check if the reservation has tablenumbers in it + foreach (string i in reservartion.Tables) + { + AvailableTables.Remove($"{i}"); //Remove the tablenumber from the available table list } } - + } } } - - - if (persons == 6 || persons == 5) { - AvailableTables = AvailableTables.Where(table => table.StartsWith("_6") && table.Length == 3).ToList(); - } else if (persons == 4 || persons == 3) { - AvailableTables = AvailableTables.Where(table => table.StartsWith("_4") && table.Length == 3).ToList(); - } else if (persons == 2) { + + + if (persons == 6 || persons == 5) + { + AvailableTables = AvailableTables.Where(table => table.StartsWith("6") && table.Length == 3).ToList(); + } + else if (persons == 4 || persons == 3) + { + AvailableTables = AvailableTables.Where(table => table.StartsWith("4") && table.Length == 3).ToList(); + } + else if (persons == 2) + { AvailableTables = AvailableTables.Where(table => table.Length == 2).ToList(); - } else if (persons == 1) { + } + else if (persons == 1) + { AvailableTables = AvailableTables.Where(table => char.IsLetter(table[0])).ToList(); } @@ -46,13 +59,17 @@ public static List CheckTables(DateTime date, TimeSpan timeslot, int per } - public static bool TableChecker(string table) { + public static bool TableChecker(string table) + { //Check if the tablenumber excist - if(AvailableTables.Contains(table)) { + if (AvailableTables.Contains(table)) + { return true; - } else { + } + else + { return false; } } - } + } } \ No newline at end of file diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 5c02847..2e0918c 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -68,13 +68,24 @@ public void Reserveren() email = emailCheck; Console.Clear(); - int amountPeopleCheck; + bool isValidAmount = false; + do { Console.WriteLine("Hoeveel mensen zullen er zijn inclusief u?"); - amountPeopleCheck = Convert.ToInt32(Console.ReadLine()); - } while (amountPeopleCheck <= 0); + string input = Console.ReadLine(); + + if (int.TryParse(input, out amountPeopleCheck) && amountPeopleCheck > 0) + { + isValidAmount = true; + } + else + { + Console.WriteLine("Ongeldige invoer. Voer een geldig aantal mensen in."); + } + } while (!isValidAmount); + amt_people = amountPeopleCheck; @@ -175,11 +186,11 @@ public void Reserveren() { Console.WriteLine("Welke tafel wilt u? (bijv. 4E of 2)"); tableCheck = Console.ReadLine(); - } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"_{tableCheck.ToUpper()}")); + } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"{tableCheck.ToUpper()}")); id = ReservationLogic.GetLastID() + 1; - if (TableLogic.TableChecker($"_{tableCheck.ToUpper()}")) + if (TableLogic.TableChecker($"{tableCheck.ToUpper()}")) { tables.Add(tableCheck); try @@ -188,6 +199,8 @@ public void Reserveren() Console.WriteLine("Gelukt!"); EmailFunction.sendmail(email, name, reservationcode, date, timeslot); EmailFunction.warning(); + // terug naar de menu uitgelogd + Menu.Start(); } catch { @@ -212,11 +225,22 @@ public void Reserveren(int client_id, string username) email = AccountResult.EmailAddress; int amountPeopleCheck; + bool isValidAmount = false; + do { Console.WriteLine("Hoeveel mensen zullen er zijn inclusief u?"); - amountPeopleCheck = Convert.ToInt32(Console.ReadLine()); - } while (amountPeopleCheck <= 0); + string input = Console.ReadLine(); + + if (int.TryParse(input, out amountPeopleCheck) && amountPeopleCheck > 0) + { + isValidAmount = true; + } + else + { + Console.WriteLine("Ongeldige invoer. Voer een geldig aantal mensen in."); + } + } while (!isValidAmount); amt_people = amountPeopleCheck; @@ -319,23 +343,27 @@ public void Reserveren(int client_id, string username) { Console.WriteLine("Welke tafel wilt u? (bijv. 4E of 2)"); tableCheck = Console.ReadLine(); - } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"_{tableCheck.ToUpper()}")); + } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"{tableCheck.ToUpper()}")); id = ReservationLogic.GetLastID() + 1; - if (TableLogic.TableChecker($"_{tableCheck.ToUpper()}")) + if (TableLogic.TableChecker($"{tableCheck.ToUpper()}")) { tables.Add(tableCheck); try { ReservationLogic.AddReservation(id, clientnumber, name, email, date, reservationcode, timeslot, tables, amt_people); - Console.WriteLine("Geluk!"); + Console.WriteLine("Gelukt!"); EmailFunction.sendmail(email, name, reservationcode, date, timeslot); EmailFunction.warning(); + // console read en dan terug naar de ingelogde scherm + Console.ReadKey(); + Console.WriteLine("druk op een toets om terug te gaan naar de menu"); + CustomerMenu.Start(username, client_id); } catch (Exception e) { - Console.WriteLine("Niet Geluk!"); + Console.WriteLine("Niet Gelukt!"); return; } diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 4f51711..9e31838 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -158,19 +158,21 @@ static public void ChangeReservation() if (r != null) { - if (r.Count > 1) { - List r_choices = new List {}; - foreach (ReservationModel reservation in r) { + if (r.Count > 1) + { + List r_choices = new List { }; + foreach (ReservationModel reservation in r) + { r_choices.Add($"[{reservation.ID}] {reservation.ToString()}"); } string[] Array_r_choices = r_choices.ToArray(); - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {$"Er zijn meerdere reserveringen gevonden met de zoekterm: {Searchterm}", "Kies de juiste reservering"}, Array_r_choices); - + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { $"Er zijn meerdere reserveringen gevonden met de zoekterm: {Searchterm}", "Kies de juiste reservering" }, Array_r_choices); + Searchterm = Array_r_choices[selectedClass].Split("]")[0].Remove(0, 1); - - } + + } string Name; do @@ -207,7 +209,7 @@ static public void ChangeReservation() Amt_People = Console.ReadLine(); } while (ValidationLogic.IsNumeric(Amt_People) != true); - Console.WriteLine("Beschikbare tafels: " + string.Join(", ", TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Convert.ToInt32(Amt_People)).Select(x => x.Substring(1)).ToList())); + Console.WriteLine("Beschikbare tafels: " + string.Join(", ", TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Convert.ToInt32(Amt_People)))); Console.WriteLine("Tafel nummers"); List Tables = new List(); while (true) From 538a017f26ae7af6494a227e99f209d833d2b9e8 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Thu, 8 Jun 2023 11:24:36 +0200 Subject: [PATCH 31/63] dubbele medewerker continue menu verwijder --- Presentation/Menu.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index a74b7df..9a16b00 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -73,10 +73,4 @@ static public void Continue(AccountModel persoon) CustomerMenu.Start(persoon.FullName, persoon.Id); } } - // medewerker gedeelte ------------------------------------------------------------------------- medewerker gedeelte - static public void Worker(int id, string username) - { - Console.WriteLine($"Welkom Worker: {username}"); - WorkerMenu.Start(username, id); - } } \ No newline at end of file From 17045ed485588f5fe3b8acd1cb8aef96f08eb175 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 12:59:33 +0200 Subject: [PATCH 32/63] benaming aangepast locatie --- DataSources/Informatie.json | 2 +- Presentation/Show.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DataSources/Informatie.json b/DataSources/Informatie.json index 616ebf2..aac4c18 100644 --- a/DataSources/Informatie.json +++ b/DataSources/Informatie.json @@ -1,5 +1,5 @@ { - "Name": "Jake\u0027s restaurant", + "Name": "Jake", "Address": "Wijnhaven 107", "Phone": "0695684596", "Email": "JakeRestaurant@gmail.com", diff --git a/Presentation/Show.cs b/Presentation/Show.cs index 5e8763a..76aafec 100644 --- a/Presentation/Show.cs +++ b/Presentation/Show.cs @@ -202,7 +202,7 @@ public class LocationPresentation { public static void ShowLocation(Location location) { - Console.WriteLine("Locatie: " + location.Name); + Console.WriteLine("Naam: " + location.Name); Console.WriteLine("Adres: " + location.Address); Console.WriteLine("Telefoon: " + location.Phone); Console.WriteLine("E-mail: " + location.Email); From 8ed8cc0ddd2e0817ed1ea808115f5676593f40bf Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 13:33:43 +0200 Subject: [PATCH 33/63] openingstijden per dag aanpassen --- DataSources/Informatie.json | 2 +- Logic/InformatieLogic.cs | 45 +++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/DataSources/Informatie.json b/DataSources/Informatie.json index aac4c18..5d1e421 100644 --- a/DataSources/Informatie.json +++ b/DataSources/Informatie.json @@ -6,7 +6,7 @@ "Website": null, "OpeningHours": { "zondag": "18:00-22:00", - "maandag": "18:00-22:00", + "maandag": "17:00-22:00", "dinsdag": "18:00-22:00", "woensdag": "18:00-22:00", "donderdag": "18:00-22:00", diff --git a/Logic/InformatieLogic.cs b/Logic/InformatieLogic.cs index 8137b16..24ac517 100644 --- a/Logic/InformatieLogic.cs +++ b/Logic/InformatieLogic.cs @@ -10,14 +10,16 @@ public static void UpdateLocation(string username, int id) bool menu = true; do { - int selectedOption = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, - "Save Changes", - "Annuleren", - $"Name: {location.Name}", - $"Address: {location.Address}", - $"Phone: {location.Phone}", - $"Email: {location.Email}", - $"Opening Hours: \n{GetFormattedOpeningHours(location.OpeningHours)}"); + int selectedOption = MenuLogic.MultipleChoice(true, "", + 1, + new string[] { }, + "Save Changes", + "Annuleren", + $"Name: {location.Name}", + $"Address: {location.Address}", + $"Phone: {location.Phone}", + $"Email: {location.Email}", + $"Opening Hours:\n{GetFormattedOpeningHours(location.OpeningHours)}"); switch (selectedOption) { @@ -32,7 +34,7 @@ public static void UpdateLocation(string username, int id) } else { - Console.WriteLine("No changes were made. Nothing to save."); + Console.WriteLine("geen veranderingen, niks om op te slaan."); // ga terug naar admin menu menu = false; } @@ -44,43 +46,48 @@ public static void UpdateLocation(string username, int id) break; case 2: // Name - Console.Write("Enter the new name: "); + Console.Write("Vul een nieuwe naam in: "); string newName = Console.ReadLine(); location.Name = newName; isModified = true; break; case 3: // Address - Console.Write("Enter the new address: "); + Console.Write("Vul een nieuwe adres in: "); string newAddress = Console.ReadLine(); location.Address = newAddress; isModified = true; break; case 4: // Phone - Console.Write("Enter the new phone number: "); + Console.Write("Vul een nieuwe telefoon nummer in: "); string newPhone = Console.ReadLine(); location.Phone = newPhone; isModified = true; break; case 5: // Email - Console.Write("Enter the new email address: "); + Console.Write("Vul een nieuwe email adress in: "); string newEmail = Console.ReadLine(); location.Email = newEmail; isModified = true; break; case 6: // Opening Hours - Dictionary newOpeningHours = new Dictionary(); - foreach (var day in location.OpeningHours.Keys) + Console.WriteLine("Vul een dag in waarvan je tijden wilt aanpassen:"); + string dayToEdit = Console.ReadLine(); + + if (location.OpeningHours.ContainsKey(dayToEdit)) { - Console.Write($"Enter the new opening hours for {day}: "); + Console.Write($"Pas de openingstijden aan voor {dayToEdit}: "); string newHours = Console.ReadLine(); - newOpeningHours.Add(day, newHours); + location.OpeningHours[dayToEdit] = newHours; + isModified = true; + } + else + { + Console.WriteLine($"Invalid day: {dayToEdit}"); } - location.OpeningHours = newOpeningHours; - isModified = true; break; } } while (menu); From 3a7821771646e1dcc0fc26397a950ea491763722 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 13:56:40 +0200 Subject: [PATCH 34/63] datamodels van maruf nullable gemaakt --- DataModels/FoodModel.cs | 4 ++-- DataModels/Location.cs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/DataModels/FoodModel.cs b/DataModels/FoodModel.cs index 33004b3..b3eb3d6 100644 --- a/DataModels/FoodModel.cs +++ b/DataModels/FoodModel.cs @@ -2,8 +2,8 @@ public class MenuItem // losse item class { public int ID { get; set; } - public string Category { get; set; } - public string Name { get; set; } + public string? Category { get; set; } + public string? Name { get; set; } public decimal Price { get; set; } } public class Foodmenu diff --git a/DataModels/Location.cs b/DataModels/Location.cs index db6f734..b92136b 100644 --- a/DataModels/Location.cs +++ b/DataModels/Location.cs @@ -1,11 +1,12 @@ using System.Text.Json; + public class Location { public string Name { get; set; } public string Address { get; set; } public string Phone { get; set; } public string Email { get; set; } - public string Website { get; set; } + public string? Website { get; set; } public Dictionary OpeningHours { get; set; } public Location(string name, string address, string phone, string email, Dictionary openingHours) @@ -17,10 +18,10 @@ public Location(string name, string address, string phone, string email, Diction OpeningHours = openingHours; } - public static Location CreateLocation() + public static Location? CreateLocation() { string json = File.ReadAllText(@"DataSources/Informatie.json"); - Location location = JsonSerializer.Deserialize(json); + Location? location = JsonSerializer.Deserialize(json); return location; } @@ -30,9 +31,10 @@ public void SaveToJsonFile(string filePath) string json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(filePath, json); } - public static Location ReadLocationFromJson(string filePath) + + public static Location? ReadLocationFromJson(string filePath) { string json = File.ReadAllText(filePath); return JsonSerializer.Deserialize(json); } -} \ No newline at end of file +} From 421fb27effe2c6af82a7fbf0192a534df5788c0e Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 13:59:39 +0200 Subject: [PATCH 35/63] accountslogic nullable --- Logic/AccountsLogic.cs | 102 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/Logic/AccountsLogic.cs b/Logic/AccountsLogic.cs index 90d4ecd..42f177f 100644 --- a/Logic/AccountsLogic.cs +++ b/Logic/AccountsLogic.cs @@ -7,73 +7,73 @@ //This class is not static so later on we can use inheritance and interfaces class AccountsLogic { - private List _accounts; + private List _accounts; - //Static properties are shared across all instances of the class - //This can be used to get the current logged in account from anywhere in the program - //private set, so this can only be set by the class itself - static public AccountModel? CurrentAccount { get; private set; } - - public AccountsLogic() - { - _accounts = AccountsAccess.LoadAll(); - } + //Static properties are shared across all instances of the class + //This can be used to get the current logged in account from anywhere in the program + //private set, so this can only be set by the class itself + static public AccountModel? CurrentAccount { get; private set; } + public AccountsLogic() + { + _accounts = AccountsAccess.LoadAll(); + } - public void UpdateList(AccountModel acc) - { - //Find if there is already an model with the same id - int index = _accounts.FindIndex(s => s.Id == acc.Id); - if (index != -1) + public void UpdateList(AccountModel acc) { - //update existing model - _accounts[index] = acc; + //Find if there is already an model with the same id + int index = _accounts.FindIndex(s => s.Id == acc.Id); + + if (index != -1) + { + //update existing model + _accounts[index] = acc; + } + else + { + //add new model + _accounts.Add(acc); + } + + AccountsAccess.WriteAll(_accounts); } - else + + public AccountModel? GetById(int id) { - //add new model - _accounts.Add(acc); + return _accounts.Find(i => i.Id == id); } - AccountsAccess.WriteAll(_accounts); - } - - public AccountModel GetById(int id) - { - return _accounts.Find(i => i.Id == id); - } - - public AccountModel GetByEmail(string email) - { - return _accounts.Find(i => i.EmailAddress == email); - } - - public AccountModel CheckLogin(string email, string password) - { - if (email == null || password == null) + public AccountModel? GetByEmail(string email) { - return null; + return _accounts.Find(i => i.EmailAddress == email); } - CurrentAccount = _accounts.Find(i => i.EmailAddress == email && i.Password == password); - return CurrentAccount; - } - public AccountModel CheckRegistration(string email) - { - if (email == null) + public AccountModel? CheckLogin(string email, string password) { - return null; + if (email == null || password == null) + { + return null; + } + CurrentAccount = _accounts.Find(i => i.EmailAddress == email && i.Password == password); + return CurrentAccount; } - CurrentAccount = _accounts.Find(i => i.EmailAddress == email); - return CurrentAccount; - } + public AccountModel? CheckRegistration(string email) + { + if (email == null) + { + return null; + } + + CurrentAccount = _accounts.Find(i => i.EmailAddress == email); + return CurrentAccount; + } - public int GetLastID() - { - return _accounts.Last().Id; - } + public int GetLastID() + { + return _accounts.Last().Id; + } } From 6342f5eb10572c5d3df1418ed3e25153885e69fa Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 14:24:24 +0200 Subject: [PATCH 36/63] Food_aanpass nullable gemaakt --- Logic/Food_Aanpassen.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Logic/Food_Aanpassen.cs b/Logic/Food_Aanpassen.cs index fedd076..24f52d9 100644 --- a/Logic/Food_Aanpassen.cs +++ b/Logic/Food_Aanpassen.cs @@ -8,8 +8,8 @@ public static void EditMenu(string username, int id) Console.WriteLine("[3] Gangen menu prijs aanpassen"); Console.WriteLine("[T] Terug"); - string input = Console.ReadLine(); - switch (input.ToUpper()) + string? input = Console.ReadLine(); + switch (input?.ToUpper()) { case "1": AddItem(username, id); @@ -39,7 +39,7 @@ public static void AddItem(string username, int id) { Console.WriteLine("Voer de categorie in: (Starters/Soups/Mains/Desserts/Drinks/Wijn)"); Console.WriteLine("*Hoofdletter gevoelig"); - string category = Console.ReadLine(); + string? category = Console.ReadLine(); // Check if the category is valid switch (category) @@ -58,7 +58,7 @@ public static void AddItem(string username, int id) } Console.WriteLine("Voer de naam in:"); - string name = Console.ReadLine(); + string? name = Console.ReadLine(); // Check if the name is not empty if (string.IsNullOrWhiteSpace(name)) @@ -97,7 +97,7 @@ public static void RemoveItem(string username, int user_id) { Console.WriteLine("Voer de categorie in: (Starters/Soups/Mains/Desserts/Drinks/Wijn)"); Console.WriteLine("*Hoofdletter gevoelig"); - string category = Console.ReadLine(); + string? category = Console.ReadLine(); string filenaam = @"DataSources/menu.json"; // Check if the category is valid switch (category) @@ -118,13 +118,19 @@ public static void RemoveItem(string username, int user_id) // ask for the ID of the item the user wants to remove Console.WriteLine("Voer de ID in van het item dat je wilt verwijderen:"); - int id = int.Parse(Console.ReadLine()); + string? input = Console.ReadLine(); + int id; + while (!int.TryParse(input, out id)) + { + Console.WriteLine("Invalid input. Please enter a valid ID:"); + input = Console.ReadLine(); + } // get the menu from the JSON file Foodmenu menu = MenuImporter.ImportFromJson(filenaam); // find the item in the menu based on the category and ID - MenuItem itemToRemove = null; + MenuItem? itemToRemove = null; switch (category) { case "Starters": @@ -191,7 +197,7 @@ public static void ChangePrice(string username, int user_id) // let the admin choose what menu price he wants to change int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "2 Gangen menu", "3 Gangen menu", "4 Gangen menu", "Wijn arrangement"); - MenuItem GangenMenu = null; + MenuItem? GangenMenu = null; switch (selectedClass) { case 0: @@ -235,7 +241,7 @@ public static void ChangePrice(string username, int user_id) ManagerMenu.Admin_menu(username, user_id); // return to the admin menu } - private static MenuItem GetGangenMenu(int id, List items) + private static MenuItem? GetGangenMenu(int id, List items) { foreach (MenuItem item in items) { From 6a74414150774797b8390753c6e6134bdfe35cad Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 14:36:46 +0200 Subject: [PATCH 37/63] Foodmenu nullable --- Logic/FoodMenu.cs | 67 +++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/Logic/FoodMenu.cs b/Logic/FoodMenu.cs index 99a7714..3e819bb 100644 --- a/Logic/FoodMenu.cs +++ b/Logic/FoodMenu.cs @@ -6,7 +6,7 @@ public class MenuImporter public static int GetNextId(Foodmenu menu) { // Get the last item in the last non-empty menu category - MenuItem lastItem = menu.Drinks.LastOrDefault() ?? menu.Desserts.LastOrDefault() ?? menu.Mains.LastOrDefault() ?? menu.Starters.LastOrDefault(); + MenuItem? lastItem = menu.Drinks.LastOrDefault() ?? menu.Desserts.LastOrDefault() ?? menu.Mains.LastOrDefault() ?? menu.Starters.LastOrDefault(); // If there are no items in the menu, start with ID 1 if (lastItem == null) @@ -25,42 +25,45 @@ public static Foodmenu ImportFromJson(string filename) string json = File.ReadAllText(filename); // deserialize the JSON data into a dynamic object - dynamic data = JsonConvert.DeserializeObject(json); + dynamic? data = JsonConvert.DeserializeObject(json); // create a new instance of the Foodmenu class Foodmenu menu = new Foodmenu(); // add the menu items to the corresponding lists - foreach (var item in data.Starters) + if (data != null) { - menu.Starters.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); - } - - foreach (var item in data.Mains) - { - menu.Mains.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); - } - - foreach (var item in data.Desserts) - { - menu.Desserts.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); - } - - foreach (var item in data.Drinks) - { - menu.Drinks.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); - } - foreach (var item in data.Wijn) - { - menu.Wijn.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); - } - foreach (var item in data.Soups) - { - menu.Soups.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); - } - foreach (var item in data.Gangen) - { - menu.Gangen.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + foreach (var item in data.Starters) + { + menu.Starters.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } + + foreach (var item in data.Mains) + { + menu.Mains.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } + + foreach (var item in data.Desserts) + { + menu.Desserts.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } + + foreach (var item in data.Drinks) + { + menu.Drinks.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } + foreach (var item in data.Wijn) + { + menu.Wijn.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } + foreach (var item in data.Soups) + { + menu.Soups.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } + foreach (var item in data.Gangen) + { + menu.Gangen.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); + } } return menu; } @@ -144,7 +147,7 @@ public static void RemoveItem(Foodmenu menu, string category, int id, string fil } // Find the item with the specified ID in the list - MenuItem item = itemList.FirstOrDefault(i => i.ID == id); + MenuItem? item = itemList.FirstOrDefault(i => i.ID == id); // If the item was not found, display an error message and return if (item == null) From 7a0e5b511651b6dcec4307253b045c3b666068a0 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 14:43:36 +0200 Subject: [PATCH 38/63] Informatielogic nullable --- Logic/InformatieLogic.cs | 161 ++++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 79 deletions(-) diff --git a/Logic/InformatieLogic.cs b/Logic/InformatieLogic.cs index 24ac517..acbe48b 100644 --- a/Logic/InformatieLogic.cs +++ b/Logic/InformatieLogic.cs @@ -4,93 +4,96 @@ public class RestaurantInformatie { public static void UpdateLocation(string username, int id) { - Location location = Location.CreateLocation(); + Location? location = Location.CreateLocation(); bool isModified = false; // Flag to track if any changes were made bool menu = true; - do + if (location != null) { - int selectedOption = MenuLogic.MultipleChoice(true, "", - 1, - new string[] { }, - "Save Changes", - "Annuleren", - $"Name: {location.Name}", - $"Address: {location.Address}", - $"Phone: {location.Phone}", - $"Email: {location.Email}", - $"Opening Hours:\n{GetFormattedOpeningHours(location.OpeningHours)}"); - - switch (selectedOption) + do { - case 0: - // Save Changes - if (isModified) - { - // Save the updated location to a JSON file - location.SaveToJsonFile(@"DataSources/Informatie.json"); - // ga terug naar admin menu - menu = false; - } - else - { - Console.WriteLine("geen veranderingen, niks om op te slaan."); + int selectedOption = MenuLogic.MultipleChoice(true, "", + 1, + new string[] { }, + "Save Changes", + "Annuleren", + $"Name: {location.Name}", + $"Address: {location.Address}", + $"Phone: {location.Phone}", + $"Email: {location.Email}", + $"Opening Hours:\n{GetFormattedOpeningHours(location.OpeningHours)}"); + + switch (selectedOption) + { + case 0: + // Save Changes + if (isModified) + { + // Save the updated location to a JSON file + location.SaveToJsonFile(@"DataSources/Informatie.json"); + // ga terug naar admin menu + menu = false; + } + else + { + Console.WriteLine("geen veranderingen, niks om op te slaan."); + // ga terug naar admin menu + menu = false; + } + break; + case 1: + // Annuleren // ga terug naar admin menu menu = false; - } - break; - case 1: - // Annuleren - // ga terug naar admin menu - menu = false; - break; - case 2: - // Name - Console.Write("Vul een nieuwe naam in: "); - string newName = Console.ReadLine(); - location.Name = newName; - isModified = true; - break; - case 3: - // Address - Console.Write("Vul een nieuwe adres in: "); - string newAddress = Console.ReadLine(); - location.Address = newAddress; - isModified = true; - break; - case 4: - // Phone - Console.Write("Vul een nieuwe telefoon nummer in: "); - string newPhone = Console.ReadLine(); - location.Phone = newPhone; - isModified = true; - break; - case 5: - // Email - Console.Write("Vul een nieuwe email adress in: "); - string newEmail = Console.ReadLine(); - location.Email = newEmail; - isModified = true; - break; - case 6: - // Opening Hours - Console.WriteLine("Vul een dag in waarvan je tijden wilt aanpassen:"); - string dayToEdit = Console.ReadLine(); - - if (location.OpeningHours.ContainsKey(dayToEdit)) - { - Console.Write($"Pas de openingstijden aan voor {dayToEdit}: "); - string newHours = Console.ReadLine(); - location.OpeningHours[dayToEdit] = newHours; + break; + case 2: + // Name + Console.Write("Vul een nieuwe naam in: "); + string? newName = Console.ReadLine() ?? string.Empty; + location.Name = newName; isModified = true; - } - else - { - Console.WriteLine($"Invalid day: {dayToEdit}"); - } - break; - } - } while (menu); + break; + case 3: + // Address + Console.Write("Vul een nieuwe adres in: "); + string? newAddress = Console.ReadLine() ?? string.Empty; + location.Address = newAddress; + isModified = true; + break; + case 4: + // Phone + Console.Write("Vul een nieuwe telefoon nummer in: "); + string? newPhone = Console.ReadLine() ?? string.Empty; + location.Phone = newPhone; + isModified = true; + break; + case 5: + // Email + Console.Write("Vul een nieuwe email adress in: "); + string? newEmail = Console.ReadLine(); + location.Email = newEmail ?? string.Empty; + isModified = true; + break; + case 6: + // Opening Hours + Console.WriteLine("Vul een dag in waarvan je tijden wilt aanpassen:"); + string? dayToEdit = Console.ReadLine(); + + if (dayToEdit != null && location.OpeningHours.ContainsKey(dayToEdit)) + { + Console.Write($"Pas de openingstijden aan voor {dayToEdit}: "); + string? newHours = Console.ReadLine() ?? string.Empty; + location.OpeningHours[dayToEdit] = newHours; + isModified = true; + } + else + { + Console.WriteLine($"Invalid day: {dayToEdit}"); + } + break; + } + } while (menu); + } // Return to the admin menu\ ManagerMenu.Admin_menu(username, id);// zodat je terug gaat } From b2a1da822a5d1468593c38efe542912bcf624dbb Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 14:48:31 +0200 Subject: [PATCH 39/63] Prijs nullable gemaakt --- Logic/Prijs.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Logic/Prijs.cs b/Logic/Prijs.cs index 588e603..203ed11 100644 --- a/Logic/Prijs.cs +++ b/Logic/Prijs.cs @@ -62,11 +62,11 @@ public decimal prijs(int aantal) while (!validInput) { Console.WriteLine($"Hoeveel van de {aantal} personen zijn 12 jaar of jonger?"); - string inputOnder12 = Console.ReadLine(); + string? inputOnder12 = Console.ReadLine(); onder_12 = string.IsNullOrEmpty(inputOnder12) ? 0 : Convert.ToInt32(inputOnder12); Console.WriteLine($"Hoeveel van de {aantal} personen willen het wijnarrangement ({wijn_arrangement})?"); - string inputWineCount = Console.ReadLine(); + string? inputWineCount = Console.ReadLine(); wineCount = string.IsNullOrEmpty(inputWineCount) ? 0 : Convert.ToInt32(inputWineCount); From c607c6a9d60d25543ee09d13e2aba0c7a9666d6c Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 14:57:27 +0200 Subject: [PATCH 40/63] manager menu nullable --- Presentation/ManagerMenu.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Presentation/ManagerMenu.cs b/Presentation/ManagerMenu.cs index 3fff501..e8317b7 100644 --- a/Presentation/ManagerMenu.cs +++ b/Presentation/ManagerMenu.cs @@ -81,8 +81,11 @@ static public void Admin_menu(string username, int id) { case 0: // start de locatie class en show detail - Location location = Location.CreateLocation(); - LocationPresentation.ShowLocation(location); + Location? location = Location.CreateLocation(); + if (location != null) + { + LocationPresentation.ShowLocation(location); + } Console.ReadKey(); Admin_menu(username, id); break; From f696ac6872b77d0bda534b14f1c962a7bc0ae192 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 14:58:23 +0200 Subject: [PATCH 41/63] customer menu nullable --- Presentation/CustomerMenu.cs | 87 +++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/Presentation/CustomerMenu.cs b/Presentation/CustomerMenu.cs index ca92c33..dd8e1f8 100644 --- a/Presentation/CustomerMenu.cs +++ b/Presentation/CustomerMenu.cs @@ -1,49 +1,52 @@ namespace Project_B.Logic; public class CustomerMenu { - static public void Start(string username, int id) // ingelogd geef parameter's mee om aan te geven dat de persoon is ingelogd - { - - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Menu bekijken", "Reserveren", "Mijn reservering", "Restaurant informatie", "Mijn gegevens", "Log uit"); - if (selectedClass == 0) - { - // voor stellen om een foto te laten up poppen van een menu kaart, anders vraag wat precies geshowed moet worden - MenuPresentation.Menu(); - Console.ReadKey(); - Start(username, id); - } - else if (selectedClass == 1) - { - // ga naar reserveren waar je een paar optie's weer krijgt - // Reservatie res = new Reservatie(); - ReservationConsole res = new ReservationConsole(); - res.Reserveren(id, username); - } - else if (selectedClass == 2) - { - // start de locatie class en show detail - MyReservation.ShowReservationInfo(username, id, MyReservation.GetReservationCode(username, id)); - Start(username, id); - } - else if (selectedClass == 3) + static public void Start(string username, int id) // ingelogd geef parameter's mee om aan te geven dat de persoon is ingelogd { - // start de locatie class en show detail - Location location = Location.CreateLocation(); - LocationPresentation.ShowLocation(location); - Start(username, id); - } - else if (selectedClass == 4) - { - AccountData.Start(id); - } - else if (selectedClass == 5) - { - // roep welkom aan sinds je word uitgelogd - Welkom.welkom(); - // je word gestuurd naar start aka je bent uitgelogd' - Menu.Start(); - } + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, "Menu bekijken", "Reserveren", "Mijn reservering", "Restaurant informatie", "Mijn gegevens", "Log uit"); + if (selectedClass == 0) + { + // voor stellen om een foto te laten up poppen van een menu kaart, anders vraag wat precies geshowed moet worden + MenuPresentation.Menu(); + Console.ReadKey(); + Start(username, id); + } + else if (selectedClass == 1) + { + // ga naar reserveren waar je een paar optie's weer krijgt + // Reservatie res = new Reservatie(); + ReservationConsole res = new ReservationConsole(); + res.Reserveren(id, username); + } + else if (selectedClass == 2) + { + // start de locatie class en show detail + MyReservation.ShowReservationInfo(username, id, MyReservation.GetReservationCode(username, id)); + Start(username, id); + } + else if (selectedClass == 3) + { + // start de locatie class en show detail + Location? location = Location.CreateLocation(); + if (location != null) + { + LocationPresentation.ShowLocation(location); + } + Start(username, id); + } + else if (selectedClass == 4) + { + AccountData.Start(id); + } + + else if (selectedClass == 5) + { + // roep welkom aan sinds je word uitgelogd + Welkom.welkom(); + // je word gestuurd naar start aka je bent uitgelogd' + Menu.Start(); + } - } + } } \ No newline at end of file From f03181aef2edb72ea53378f5bddc696e29ea7698 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 15:02:43 +0200 Subject: [PATCH 42/63] mederwerkers.cs nullable --- Presentation/Mederwerker.cs | 46 ++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/Presentation/Mederwerker.cs b/Presentation/Mederwerker.cs index bf7b540..3633c49 100644 --- a/Presentation/Mederwerker.cs +++ b/Presentation/Mederwerker.cs @@ -9,22 +9,25 @@ public static void Toevoeg_Mederwerker_Menu(string username, int id) // Mederwerker menu Console.WriteLine("[1] Persoon toevoegen"); Console.WriteLine("[T] Terug gaan"); - string input = Console.ReadLine(); - switch (input.ToUpper()) + string? input = Console.ReadLine(); + if (input != null) { - case "1": - // persoon toevoegen - // ga eerst naar functie die vraagt voor gegevens - Mederwerker_gegevens(username, id); - break; - case "T": - ManagerMenu.Admin_menu(username, id);// zodat je terug gaat - // code block - break; - default: - Console.WriteLine("Ongeldige optie. Kies opnieuw."); - Toevoeg_Mederwerker_Menu(username, id); - break; + switch (input.ToUpper()) + { + case "1": + // persoon toevoegen + // ga eerst naar functie die vraagt voor gegevens + Mederwerker_gegevens(username, id); + break; + case "T": + ManagerMenu.Admin_menu(username, id);// zodat je terug gaat + // code block + break; + default: + Console.WriteLine("Ongeldige optie. Kies opnieuw."); + Toevoeg_Mederwerker_Menu(username, id); + break; + } } } public static void Mederwerker_gegevens(string username, int id) @@ -32,16 +35,21 @@ public static void Mederwerker_gegevens(string username, int id) AccountsLogic accountsLogic = new AccountsLogic(); Console.WriteLine("Voer de gegevens van de medewerker in:"); Console.Write("E-mailadres: "); - string emailAddress = Console.ReadLine(); + string? emailAddress = Console.ReadLine(); Console.Write("Wachtwoord: "); - string password = Console.ReadLine(); + string? password = Console.ReadLine(); Console.Write("Volledige naam: "); - string fullName = Console.ReadLine(); + string? fullName = Console.ReadLine(); // create new employee object - AccountModel newEmployee = new AccountModel(accountsLogic.GetLastID() + 1, emailAddress, password, fullName, 2); + AccountModel newEmployee = new AccountModel( + accountsLogic.GetLastID() + 1, + emailAddress ?? string.Empty, + password ?? string.Empty, + fullName ?? string.Empty, + 2); // add new employee to accounts accountsLogic.UpdateList(newEmployee); From 228a1f43f97acc766debbda684a20bf539af49ab Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 15:03:12 +0200 Subject: [PATCH 43/63] Menu.cs nullable --- Presentation/Menu.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index 9a16b00..58d4af6 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -32,8 +32,11 @@ static public void Start() else if (selectedClass == 4) { // start de locatie class en show detail - Location location = Location.CreateLocation(); - LocationPresentation.ShowLocation(location); + Location? location = Location.CreateLocation(); + if (location != null) + { + LocationPresentation.ShowLocation(location); + } Console.ReadKey(); Start(); } From 1a971536a35cd5d29cd8a999a6370b9dbcb91473 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 15:07:21 +0200 Subject: [PATCH 44/63] show.cs nullable --- Presentation/Show.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Presentation/Show.cs b/Presentation/Show.cs index 76aafec..1f3c487 100644 --- a/Presentation/Show.cs +++ b/Presentation/Show.cs @@ -169,11 +169,11 @@ private static void DisplayMenuItems(List items, bool includePrice) { if (includePrice) { - Console.WriteLine(item.Name.PadRight(30, '.') + " " + item.Price.ToString("F2")); + Console.WriteLine(item.Name?.PadRight(30, '.') + " " + item.Price.ToString("F2")); } else { - Console.WriteLine(item.Name.PadRight(30, '.')); + Console.WriteLine(item.Name?.PadRight(30, '.')); } } } @@ -183,11 +183,11 @@ private static void DisplayMenuItems(List items, string naam, int id, { if (includePrice) { - Console.WriteLine(item.Name.PadRight(30, '.') + " " + item.Price.ToString("F2") + " ID: " + item.ID); + Console.WriteLine(item.Name?.PadRight(30, '.') + " " + item.Price.ToString("F2") + " ID: " + item.ID); } else { - Console.WriteLine(item.Name.PadRight(30, '.') + " ID: " + item.ID); + Console.WriteLine(item.Name?.PadRight(30, '.') + " ID: " + item.ID); } } } From c3397f473b0eb3b64a424cdecf34bbd1f65a5c5d Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 15:10:47 +0200 Subject: [PATCH 45/63] ook workermenu voor locatie showen nullable gedaan --- Presentation/CustomerMenu.cs | 1 + Presentation/WorkerMenu.cs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Presentation/CustomerMenu.cs b/Presentation/CustomerMenu.cs index dd8e1f8..5c735e1 100644 --- a/Presentation/CustomerMenu.cs +++ b/Presentation/CustomerMenu.cs @@ -33,6 +33,7 @@ static public void Start(string username, int id) // ingelogd geef parameter's m { LocationPresentation.ShowLocation(location); } + Console.ReadKey(); Start(username, id); } else if (selectedClass == 4) diff --git a/Presentation/WorkerMenu.cs b/Presentation/WorkerMenu.cs index b5d4740..23998bc 100644 --- a/Presentation/WorkerMenu.cs +++ b/Presentation/WorkerMenu.cs @@ -23,8 +23,11 @@ static public void Start(string username, int id) // ingelogd geef parameter's m else if (selectedClass == 2) { // start de locatie class en show detail - Location location = Location.CreateLocation(); - LocationPresentation.ShowLocation(location); + Location? location = Location.CreateLocation(); + if (location != null) + { + LocationPresentation.ShowLocation(location); + } Console.ReadKey(); Start(username, id); } From ef0ecd40bc416b26423af2ad2b5d027f8b3f31dd Mon Sep 17 00:00:00 2001 From: maruf128 Date: Sun, 11 Jun 2023 15:18:17 +0200 Subject: [PATCH 46/63] Files die we gekregen hebben nullable gemaakt --- DataAccess/AccountsAccess.cs | 2 +- Logic/AccountsLogic.cs | 2 +- Presentation/UserLogin.cs | 22 +++++++++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/DataAccess/AccountsAccess.cs b/DataAccess/AccountsAccess.cs index 0d1166d..ed710fa 100644 --- a/DataAccess/AccountsAccess.cs +++ b/DataAccess/AccountsAccess.cs @@ -5,7 +5,7 @@ static class AccountsAccess static string path = System.IO.Path.GetFullPath(System.IO.Path.Combine(Environment.CurrentDirectory, @"DataSources/accounts.json")); - public static List LoadAll() + public static List? LoadAll() { string json = File.ReadAllText(path); return JsonSerializer.Deserialize>(json); diff --git a/Logic/AccountsLogic.cs b/Logic/AccountsLogic.cs index 42f177f..88d9732 100644 --- a/Logic/AccountsLogic.cs +++ b/Logic/AccountsLogic.cs @@ -16,7 +16,7 @@ class AccountsLogic public AccountsLogic() { - _accounts = AccountsAccess.LoadAll(); + _accounts = AccountsAccess.LoadAll() ?? new List(); } diff --git a/Presentation/UserLogin.cs b/Presentation/UserLogin.cs index 4f75dc5..cf020c9 100644 --- a/Presentation/UserLogin.cs +++ b/Presentation/UserLogin.cs @@ -14,25 +14,25 @@ public static void Start() bool accountNull = true; while (accountNull is true) { - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, $"Email: {email}", $"Wachtwoord: {new string('*', password.Length)}", "", "Login", "Annuleren"); + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, $"Email: {email ?? "N/A"}", $"Wachtwoord: {new string('*', password?.Length ?? 0)}", "", "Login", "Annuleren"); if (selectedClass == 0) { Console.WriteLine("Graag uw email invullen."); - email = Console.ReadLine(); + email = Console.ReadLine() ?? string.Empty; } else if (selectedClass == 1) { Console.WriteLine("Graag uw wachtwoord invullen."); - password = Console.ReadLine(); + password = Console.ReadLine() ?? string.Empty; } else if (selectedClass == 4) { Menu.Start(); } - else if (selectedClass == 3) + else if (selectedClass == 3 && email != null && password != null) { accountNull = false; - AccountModel acc = accountsLogic.CheckLogin(email, password); + AccountModel? acc = accountsLogic.CheckLogin(email, password); if (acc != null) { //Console.WriteLine("Welcome back " + acc.FullName); @@ -43,7 +43,7 @@ public static void Start() string mail = acc.EmailAddress; string ww = acc.Password; - AccountModel persoon = null; + AccountModel? persoon = null; // op basis van level geef de user zn eigen model if (level == 1) // Manager { @@ -60,7 +60,15 @@ public static void Start() persoon = new Customer(id, mail, ww, naam, level); // Additional customer-specific logic here } - Menu.Continue(persoon); + if (persoon != null) + { + Menu.Continue(persoon); + } + else + { + Console.WriteLine($"Er ging iets fout! je word terug naar de menu gestuurd"); + Menu.Start(); + } } else { From 32ad58e4a7fe841cf8446cf0583f6a659cf615e7 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Mon, 12 Jun 2023 10:20:53 +0200 Subject: [PATCH 47/63] checks gemaakt zodat je niet opnieuw moet beginnen --- DataSources/menu.json | 2 +- Logic/Food_Aanpassen.cs | 41 ++++++++++++++++++++++--------------- Presentation/Mederwerker.cs | 29 ++++++++++++++++++++------ 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/DataSources/menu.json b/DataSources/menu.json index 458a531..2475272 100644 --- a/DataSources/menu.json +++ b/DataSources/menu.json @@ -106,7 +106,7 @@ "ID": 4, "Category": null, "Name": "Wijn arrangement", - "Price": 4.50 + "Price": 12.50 } ] } \ No newline at end of file diff --git a/Logic/Food_Aanpassen.cs b/Logic/Food_Aanpassen.cs index 24f52d9..c16e13e 100644 --- a/Logic/Food_Aanpassen.cs +++ b/Logic/Food_Aanpassen.cs @@ -57,24 +57,24 @@ public static void AddItem(string username, int id) return; } - Console.WriteLine("Voer de naam in:"); - string? name = Console.ReadLine(); - // Check if the name is not empty - if (string.IsNullOrWhiteSpace(name)) + string name; + do { - Console.WriteLine("Naam mag niet leeg zijn. Kies opnieuw."); - AddItem(username, id); - return; - } + Console.WriteLine("Voer de naam van het item in:"); + name = Console.ReadLine()!; + } while (string.IsNullOrWhiteSpace(name)); - Console.WriteLine("Voer de prijs in:"); - if (!decimal.TryParse(Console.ReadLine(), out decimal price)) + decimal price; + do { - Console.WriteLine("Ongeldige prijs. Kies opnieuw."); - AddItem(username, id); - return; - } + Console.WriteLine("Voer de prijs in:"); + string priceInput = Console.ReadLine()!; + if (!decimal.TryParse(priceInput, out price)) + { + Console.WriteLine("Ongeldige prijs. Kies opnieuw."); + } + } while (price <= 0); // Retrieve the menu object from the file string filenaam = @"DataSources/menu.json"; Foodmenu menu = MenuImporter.ImportFromJson(filenaam); @@ -221,9 +221,16 @@ public static void ChangePrice(string username, int user_id) // check if the menu item is found if (GangenMenu != null) { - // get the new price from the admin - Console.WriteLine($"Vul de nieuwe prijs voor {GangenMenu}:"); - decimal newPrice = Convert.ToDecimal(Console.ReadLine()); + decimal newPrice; + do + { + Console.WriteLine($"Vul de nieuwe prijs voor {GangenMenu}:"); + string newPriceInput = Console.ReadLine()!; + if (!decimal.TryParse(newPriceInput, out newPrice)) + { + Console.WriteLine("Ongeldige prijs. Kies opnieuw."); + } + } while (newPrice <= 0); // update the price of the menu item GangenMenu.Price = newPrice; diff --git a/Presentation/Mederwerker.cs b/Presentation/Mederwerker.cs index 3633c49..787059e 100644 --- a/Presentation/Mederwerker.cs +++ b/Presentation/Mederwerker.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; namespace Project_B.Logic; +using System.Text.RegularExpressions; public class Mederwerker { private const string ACCOUNT_FILE = @"DataSources/accounts.json"; @@ -34,14 +35,30 @@ public static void Mederwerker_gegevens(string username, int id) { AccountsLogic accountsLogic = new AccountsLogic(); Console.WriteLine("Voer de gegevens van de medewerker in:"); - Console.Write("E-mailadres: "); - string? emailAddress = Console.ReadLine(); + string emailAddress; + string password; + string fullName; + do + { + Console.WriteLine("Graag hier de email invullen:"); + emailAddress = Console.ReadLine()!.ToLower(); + if (!Regex.IsMatch(emailAddress, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && emailAddress != "1") + { + Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); + } + } while (!Regex.IsMatch(emailAddress, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && emailAddress != "1"); - Console.Write("Wachtwoord: "); - string? password = Console.ReadLine(); + do + { + Console.Write("Wachtwoord: "); + password = Console.ReadLine()!; + } while (string.IsNullOrWhiteSpace(password)); - Console.Write("Volledige naam: "); - string? fullName = Console.ReadLine(); + do + { + Console.Write("Volledige naam: "); + fullName = Console.ReadLine()!; + } while (string.IsNullOrWhiteSpace(fullName)); // create new employee object AccountModel newEmployee = new AccountModel( From 7c9a5824c361ea1db6db903665c707b65c270cbc Mon Sep 17 00:00:00 2001 From: Henno0701 <1048091@hr.nl> Date: Tue, 13 Jun 2023 09:38:10 +0200 Subject: [PATCH 48/63] Readkey switch --- Presentation/Reservation/ReservationConsole.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 2e0918c..3da1afc 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -357,8 +357,8 @@ public void Reserveren(int client_id, string username) EmailFunction.sendmail(email, name, reservationcode, date, timeslot); EmailFunction.warning(); // console read en dan terug naar de ingelogde scherm - Console.ReadKey(); Console.WriteLine("druk op een toets om terug te gaan naar de menu"); + Console.ReadKey(); CustomerMenu.Start(username, client_id); } catch (Exception e) From ed0e2df5476baf799b8b0ff89075d762920615b4 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 13 Jun 2023 10:51:02 +0200 Subject: [PATCH 49/63] informatie met checks --- DataSources/Informatie.json | 4 +- Logic/InformatieLogic.cs | 104 ++++++++++++++++++++++++++++++------ 2 files changed, 91 insertions(+), 17 deletions(-) diff --git a/DataSources/Informatie.json b/DataSources/Informatie.json index 5d1e421..42e8040 100644 --- a/DataSources/Informatie.json +++ b/DataSources/Informatie.json @@ -5,8 +5,8 @@ "Email": "JakeRestaurant@gmail.com", "Website": null, "OpeningHours": { - "zondag": "18:00-22:00", - "maandag": "17:00-22:00", + "zondag": "19:00-22:00", + "maandag": "18:00-22:00", "dinsdag": "18:00-22:00", "woensdag": "18:00-22:00", "donderdag": "18:00-22:00", diff --git a/Logic/InformatieLogic.cs b/Logic/InformatieLogic.cs index acbe48b..62bea05 100644 --- a/Logic/InformatieLogic.cs +++ b/Logic/InformatieLogic.cs @@ -1,5 +1,6 @@ namespace Project_B.Logic; using System.Text; +using System.Text.RegularExpressions; public class RestaurantInformatie { public static void UpdateLocation(string username, int id) @@ -47,31 +48,54 @@ public static void UpdateLocation(string username, int id) menu = false; break; case 2: - // Name - Console.Write("Vul een nieuwe naam in: "); - string? newName = Console.ReadLine() ?? string.Empty; - location.Name = newName; + // maak check if name empty ask again + string? newName; + do + { + // Name + Console.Write("Vul de nieuwe naam in: "); + newName = Console.ReadLine() ?? string.Empty; + location.Name = newName; + } while (string.IsNullOrWhiteSpace(newName)); isModified = true; break; case 3: // Address - Console.Write("Vul een nieuwe adres in: "); - string? newAddress = Console.ReadLine() ?? string.Empty; - location.Address = newAddress; + string? newAddress; + do + { + Console.Write("Vul een nieuwe adres in: "); + newAddress = Console.ReadLine() ?? string.Empty; + location.Address = newAddress; + } while (string.IsNullOrWhiteSpace(newAddress)); isModified = true; break; case 4: - // Phone - Console.Write("Vul een nieuwe telefoon nummer in: "); - string? newPhone = Console.ReadLine() ?? string.Empty; - location.Phone = newPhone; + string newPhone; + do + { + Console.Write("Vul een nieuwe telefoonnummer in: "); + newPhone = Console.ReadLine()?.Trim() ?? string.Empty; + + if (!Regex.IsMatch(newPhone, @"^\(?(0\d{2})\)?[-.\s]?(\d{3})[-.\s]?(\d{2})[-.\s]?(\d{2})$") && newPhone != "1") + { + Console.WriteLine("Ongeldig telefoonnummer. Probeer het opnieuw."); + } + } while (!Regex.IsMatch(newPhone, @"^\(?(0\d{2})\)?[-.\s]?(\d{3})[-.\s]?(\d{2})[-.\s]?(\d{2})$") && newPhone != "1"); isModified = true; break; case 5: // Email - Console.Write("Vul een nieuwe email adress in: "); - string? newEmail = Console.ReadLine(); - location.Email = newEmail ?? string.Empty; + string? newEmail; + do + { + Console.WriteLine("Graag hier de nieuwe email invullen:"); + newEmail = Console.ReadLine()!.ToLower(); + if (!Regex.IsMatch(newEmail, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && newEmail != "1") + { + Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); + } + } while (!Regex.IsMatch(newEmail, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && newEmail != "1"); isModified = true; break; case 6: @@ -82,7 +106,50 @@ public static void UpdateLocation(string username, int id) if (dayToEdit != null && location.OpeningHours.ContainsKey(dayToEdit)) { Console.Write($"Pas de openingstijden aan voor {dayToEdit}: "); - string? newHours = Console.ReadLine() ?? string.Empty; + string? Newbegintijd; + do + { + Console.WriteLine("Vul de tijd in wanneer het restaurant open gaat (HH:mm): "); + Newbegintijd = Console.ReadLine()?.Trim() ?? string.Empty; + + if (!Regex.IsMatch(Newbegintijd, @"^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$")) + { + Console.WriteLine("Ongeldige tijd. Voer een geldige tijd in in het formaat HH:mm."); + } + } while (!Regex.IsMatch(Newbegintijd, @"^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$")); + // optioneel hoeft niet niet ingevuld behoud oude eindtijd + string oudetijd = location.OpeningHours[dayToEdit]; + string[] oudegedeeltes = oudetijd.Split('-'); + // Get the second part, which represents the end time + string eindtijd = oudegedeeltes[1].Trim(); + bool doorgaan = true; + string? Neweindtijd; + do + { + Console.WriteLine($"Vul de tijd in wanneer het restaurant dicht gaat (HH:mm): (vul niks in/op enter om de oude tijd te behouden ({eindtijd}))"); + Neweindtijd = Console.ReadLine()?.Trim(); + + if (string.IsNullOrEmpty(Neweindtijd)) + { + Neweindtijd = eindtijd; // dus je behoud de oude eindtijd + doorgaan = false; + } + else if (Regex.IsMatch(Neweindtijd, @"^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$")) + { + // wnr het correct is + doorgaan = false; + } + } while (doorgaan); + // maak nu functie om te kijken of de eind tijd wel later is dan de begin tijd + if (IsEndTimeLater(Neweindtijd, Newbegintijd)) + { + Console.WriteLine("Error: End time must be later than start time. Please try again. (press enter)"); + Console.ReadKey(); + break; + } + // anders is het wel correct + // zet de 2 tijden samen + string newHours = Newbegintijd + "-" + Neweindtijd; location.OpeningHours[dayToEdit] = newHours; isModified = true; } @@ -110,4 +177,11 @@ private static string GetFormattedOpeningHours(Dictionary openin return sb.ToString(); } + private static bool IsEndTimeLater(string startTime, string endTime) + { + DateTime startDateTime = DateTime.Parse(startTime); + DateTime endDateTime = DateTime.Parse(endTime); + + return endDateTime > startDateTime; + } } From 0d1c5d4953840cd7d2af7c8c1a0c208874d6e789 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 13 Jun 2023 11:10:18 +0200 Subject: [PATCH 50/63] account data warnings weg gone loes --- Presentation/AccountData.cs | 130 +++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 63 deletions(-) diff --git a/Presentation/AccountData.cs b/Presentation/AccountData.cs index a7be266..6b6feaa 100644 --- a/Presentation/AccountData.cs +++ b/Presentation/AccountData.cs @@ -11,81 +11,85 @@ public class AccountData static public void Start(int id) // ingelogd geef parameter's mee om aan te geven dat de persoon is ingelogd { - AccountModel acc = accountsLogic.GetById(id); - - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {}, $"Email: {acc.EmailAddress}", $"Wachtwoord: {acc.Password}", $"Volledige naam: {acc.FullName}", "Mijn reserveringen", "Terug"); - if (selectedClass == 0) - { - // check syntax email, Will return an error message if not correct or the email already exists. - do - { - Console.WriteLine("Vul hier uw nieuwe email."); - acc.EmailAddress = Console.ReadLine().ToLower(); - } while (ValidationLogic.IsValidEmail(acc.EmailAddress) != true && accountsLogic.CheckRegistration(acc.EmailAddress) != null); - - // updates email to json and returns to Start - accountsLogic.UpdateList(acc); - Start(id); - } - else if (selectedClass == 1) + AccountModel? acc = accountsLogic.GetById(id); + if (acc != null) { - do{ - Console.WriteLine("Graag hier je wachtwoord invullen:"); - Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter en 1 cijfer"); - acc.Password = Console.ReadLine(); - } while (ValidationLogic.IsValidPassword(acc.Password) != true); - // updates password to json and returns to Start - accountsLogic.UpdateList(acc); - Start(id); - } - else if (selectedClass == 2) - { - do + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { }, $"Email: {acc.EmailAddress}", $"Wachtwoord: {acc.Password}", $"Volledige naam: {acc.FullName}", "Mijn reserveringen", "Terug"); + if (selectedClass == 0) { - Console.WriteLine("Graag hier je volledige naam invullen:"); - acc.FullName = Console.ReadLine().ToLower(); - if (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")) + // check syntax email, Will return an error message if not correct or the email already exists. + do + { + Console.WriteLine("Vul hier uw nieuwe email."); + acc.EmailAddress = Console.ReadLine()!.ToLower(); + } while (ValidationLogic.IsValidEmail(acc.EmailAddress) != true && accountsLogic.CheckRegistration(acc.EmailAddress) != null); + + // updates email to json and returns to Start + accountsLogic.UpdateList(acc); + Start(id); + } + else if (selectedClass == 1) { - Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); + do + { + Console.WriteLine("Graag hier je wachtwoord invullen:"); + Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter en 1 cijfer"); + acc.Password = Console.ReadLine()!; + } while (ValidationLogic.IsValidPassword(acc.Password) != true); + + // updates password to json and returns to Start + accountsLogic.UpdateList(acc); + Start(id); } - } while (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")); + else if (selectedClass == 2) + { + do + { + Console.WriteLine("Graag hier je volledige naam invullen:"); + acc.FullName = Console.ReadLine()!.ToLower(); + if (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")) + { + Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); + } + } while (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")); - // updates full name to json and returns to Start - accountsLogic.UpdateList(acc); - Start(id); - } - else if (selectedClass == 3) - { - var ReservationList = ReservationLogic.GetReservations(acc.EmailAddress); // filters all reservations with this email, maybe change this to clientnumber - Console.ForegroundColor = ConsoleColor.DarkGreen; - Console.WriteLine($"Reservaties Tabel van {acc.FullName}:"); - Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine("--------------------"); - Console.WriteLine("{0,-25} {1,-15} {2,-10} {3,-15} {4,-15} {5, -20}", "Naam", "Datum", "Tijd", "Tafel nummers", "Aantal pers.", "Reservatie code"); - foreach(ReservationModel reservation in ReservationList) + // updates full name to json and returns to Start + accountsLogic.UpdateList(acc); + Start(id); + } + else if (selectedClass == 3) { - Console.WriteLine("{0,-25} {1,-15} {2,-10} {3,-15} {4,-15} {5, -20}", - reservation.Name, reservation.Date.ToString("dd-MM-yyyy"), reservation.TimeSlot.ToString(@"hh\:mm"), string.Join(", ", reservation.Tables), reservation.Amt_People, reservation.ReservationCode); + var ReservationList = ReservationLogic.GetReservations(acc.EmailAddress); // filters all reservations with this email, maybe change this to clientnumber + Console.ForegroundColor = ConsoleColor.DarkGreen; + Console.WriteLine($"Reservaties Tabel van {acc.FullName}:"); + Console.ForegroundColor = ConsoleColor.White; + Console.WriteLine("--------------------"); + Console.WriteLine("{0,-25} {1,-15} {2,-10} {3,-15} {4,-15} {5, -20}", "Naam", "Datum", "Tijd", "Tafel nummers", "Aantal pers.", "Reservatie code"); + foreach (ReservationModel reservation in ReservationList) + { + Console.WriteLine("{0,-25} {1,-15} {2,-10} {3,-15} {4,-15} {5, -20}", + reservation.Name, reservation.Date.ToString("dd-MM-yyyy"), reservation.TimeSlot.ToString(@"hh\:mm"), string.Join(", ", reservation.Tables), reservation.Amt_People, reservation.ReservationCode); + } + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("--------------------"); + + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine("> Terug"); + Console.ForegroundColor = ConsoleColor.Gray; + string back_button = Console.ReadLine()!; + if (back_button != null) + { + Start(id); + } } - Console.ForegroundColor = ConsoleColor.Gray; - Console.WriteLine("--------------------"); - Console.ForegroundColor = ConsoleColor.Blue; - Console.WriteLine("> Terug"); - Console.ForegroundColor = ConsoleColor.Gray; - string back_button = Console.ReadLine(); - if(back_button != null) + else if (selectedClass == 4) { - Start(id); + // je wordt terug gestuurd naar de CustomerMenu + CustomerMenu.Start(acc.FullName, id); } } - - else if (selectedClass == 4) - { - // je wordt terug gestuurd naar de CustomerMenu - CustomerMenu.Start(acc.FullName, id); - } } } \ No newline at end of file From 08b22ec7216290a07026ead591343ee991c2dcaa Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 13 Jun 2023 12:45:33 +0200 Subject: [PATCH 51/63] datum word goed gechecked --- Presentation/Reservation/ReservationView.cs | 42 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 9e31838..0d9e325 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Project_B.Logic; using Project_B.DataModels; +using System.Globalization; public class Reservation { @@ -82,11 +83,27 @@ static public void MakeReservation() } string Date; + DateTime temp = DateTime.Now; + bool isValidDate = false; + do { Console.Write("Date (DD-MM-JJJJ): "); - Date = Console.ReadLine(); - } while (ValidationLogic.IsValidDate(Date) != true); + Date = Console.ReadLine()!; + + if (!DateTime.TryParseExact(Date, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)) + { + Console.WriteLine("Veerkde datum. Vul een juiste formaat in: DD-MM-JJJJ."); + } + else if (parsedDate < temp) + { + Console.WriteLine("De datum moet wel in de toekomst zitten"); + } + else + { + isValidDate = true; + } + } while (!isValidDate); string TimeSlot; @@ -189,11 +206,28 @@ static public void ChangeReservation() } while (ValidationLogic.IsValidEmail(Email) != true); string Date; + DateTime temp = DateTime.Now; + bool isValidDate = false; + do { Console.Write("Date (DD-MM-JJJJ): "); - Date = Console.ReadLine(); - } while (ValidationLogic.IsValidDate(Date) != true); + Date = Console.ReadLine()!; + + if (!DateTime.TryParseExact(Date, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)) + { + Console.WriteLine("Veerkde datum. Vul een juiste formaat in: DD-MM-JJJJ."); + } + else if (parsedDate < temp) + { + Console.WriteLine("De datum moet wel in de toekomst zitten"); + } + else + { + isValidDate = true; + } + } while (!isValidDate); + string TimeSlot; do From a371acacce7911bb8d5129f54bb3fe085767ba85 Mon Sep 17 00:00:00 2001 From: joelhogeschool <1062069@hr.nl> Date: Tue, 13 Jun 2023 13:17:24 +0200 Subject: [PATCH 52/63] updated registration baby proofed registration --- DataSources/accounts.json | 7 ++++ Logic/ValidationLogic.cs | 55 ++++++++++++++++++++++++++++---- Presentation/UserRegistration.cs | 38 ++++++++++++---------- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/DataSources/accounts.json b/DataSources/accounts.json index e6ee348..fc6719c 100644 --- a/DataSources/accounts.json +++ b/DataSources/accounts.json @@ -61,5 +61,12 @@ "password": "Abc123!", "fullName": "Henno Passchier", "level": 0 + }, + { + "id": 10, + "emailAddress": "ttt@test.nl", + "password": "Abc123", + "fullName": "qwee", + "level": 0 } ] \ No newline at end of file diff --git a/Logic/ValidationLogic.cs b/Logic/ValidationLogic.cs index c271583..e7e8532 100644 --- a/Logic/ValidationLogic.cs +++ b/Logic/ValidationLogic.cs @@ -12,13 +12,52 @@ public static class ValidationLogic { public static bool IsValidEmail(string email) { - if (!Regex.IsMatch(email, @"^[^@\s]+@[^@\s]+.[^@\s]+$")) + if (!Regex.IsMatch(email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$")) { - Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); + Console.ForegroundColor = ConsoleColor.DarkRed; + if (!Regex.IsMatch(email, @"@[^@\s]")) + { + Console.WriteLine("Je hebt geen @ in je email, voeg deze toe."); + } + if (!Regex.IsMatch(email, @"\.[^@\s]")) + { + Console.WriteLine("Je hebt geen . in je email, voeg deze toe."); + } + if (Regex.IsMatch(email, @"\s")) + { + Console.WriteLine("Je email bevat een spatie, verwijder deze"); + } + if (email.Length == 0) + { + Console.WriteLine("Je email moet minimaal 1 teken lang zijn"); + } + Console.ForegroundColor = ConsoleColor.Gray; return false; + } + return true; + } + public static bool IsValidFullname(string name) + { + if (!Regex.IsMatch(name, @"^[A-Za-z]+ [A-Za-z]+$")) + { + Console.ForegroundColor = ConsoleColor.DarkRed; + if (Regex.IsMatch(name, "[0-9]")) + { + Console.WriteLine("Je hebt een nummer in je naam, verwijder deze."); + } + if (!Regex.IsMatch(name, @"\s")) + { + Console.WriteLine("Je naam bevat geen spatie(tussen je voornaam en achternaam)"); + } + if (name.Length == 0) + { + Console.WriteLine("Je naam moet minimaal 1 teken lang zijn"); + } + Console.ForegroundColor = ConsoleColor.Gray; + return false; } - else return true; + return true; } public static bool IsValidDate(string date) @@ -48,9 +87,10 @@ public static bool AmtPeopleCheck(int number) { public static bool IsValidPassword(string pass) { - Console.ForegroundColor = ConsoleColor.DarkRed; + if (!Regex.IsMatch(pass, "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{6,}$")) { + Console.ForegroundColor = ConsoleColor.DarkRed; if (!Regex.IsMatch(pass, "[0-9]")) { Console.WriteLine("Je bent een nummer vergeten in je wachtwoord."); @@ -59,6 +99,10 @@ public static bool IsValidPassword(string pass) { Console.WriteLine("Je bent een hoofdletter vergeten in je wachtwoord."); } + if (!Regex.IsMatch(pass, "[a-z]")) + { + Console.WriteLine("Je bent een kleine letter vergeten in je wachtwoord."); + } if (pass.Length < 6) { Console.WriteLine("Het wachtwoord moet minimaal 6 tekens lang zijn"); @@ -66,14 +110,13 @@ public static bool IsValidPassword(string pass) Console.ForegroundColor = ConsoleColor.Gray; return false; } - Console.ForegroundColor = ConsoleColor.Gray; return true; } public static bool CodeExists(string code) { string json = File.ReadAllText("./DataSources/reservations.json"); // Deserialize the JSON into a list of Reservation objects - List reservations = JsonConvert.DeserializeObject>(json); + List? reservations = JsonConvert.DeserializeObject>(json); if (reservations != null) { if (!reservations.Any(r => r.reservationcode == code)) { return true; diff --git a/Presentation/UserRegistration.cs b/Presentation/UserRegistration.cs index e8776ce..e74d71f 100644 --- a/Presentation/UserRegistration.cs +++ b/Presentation/UserRegistration.cs @@ -13,37 +13,41 @@ public static void Start() { Console.WriteLine("Welkom bij de registratiepagina"); Console.WriteLine("[1] terug naar het startmenu"); - + string Email; do { - Console.WriteLine("Graag hier je email invullen:"); - Email = Console.ReadLine().ToLower(); - if (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && Email != "1") + do { - Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); - } - } while (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && Email != "1"); + Console.WriteLine("Graag hier je email invullen:"); + Email = Console.ReadLine().ToLower(); + } while ( ValidationLogic.IsValidEmail(Email) != true && Email != "1"); - if (Email == "1") - { - Menu.Start(); - return; - } + if (Email == "1") + { + Menu.Start(); + return; + } + } while (Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$") != true); - string Password; + string? Password; do { Console.WriteLine("Graag hier je wachtwoord invullen:"); - Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter en 1 cijfer"); + Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter, 1 kleine letter en 1 cijfer"); Password = Console.ReadLine(); } while (ValidationLogic.IsValidPassword(Password) != true); - Console.WriteLine("Graag hier je volledige naam invullen:"); - string FullName = Console.ReadLine(); + string FullName; + do + { + Console.WriteLine("Graag hier je volledige naam invullen:"); + Console.WriteLine("De juiste syntax is minimaal 1 letter lang en bevat geen nummers"); + FullName = Console.ReadLine(); + } while (ValidationLogic.IsValidFullname(FullName) != true); - AccountModel acc = accountsLogic.CheckRegistration(Email); + AccountModel? acc = accountsLogic.CheckRegistration(Email); if (acc == null) { AccountModel newAcc = new AccountModel(accountsLogic.GetLastID() + 1, Email, Password, FullName, Level); From 57457283f2dd29142de4e443bced0a30c5633f35 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 13 Jun 2023 13:25:47 +0200 Subject: [PATCH 53/63] nullable weg en validation gebruik ipv zelf kijken --- Presentation/Mederwerker.cs | 12 ++-- Presentation/UserRegistration.cs | 98 ++++++++++++++++---------------- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/Presentation/Mederwerker.cs b/Presentation/Mederwerker.cs index 787059e..27c9330 100644 --- a/Presentation/Mederwerker.cs +++ b/Presentation/Mederwerker.cs @@ -42,7 +42,7 @@ public static void Mederwerker_gegevens(string username, int id) { Console.WriteLine("Graag hier de email invullen:"); emailAddress = Console.ReadLine()!.ToLower(); - if (!Regex.IsMatch(emailAddress, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && emailAddress != "1") + if (ValidationLogic.IsValidEmail(emailAddress) != true && emailAddress != "1") { Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); } @@ -50,15 +50,17 @@ public static void Mederwerker_gegevens(string username, int id) do { - Console.Write("Wachtwoord: "); + Console.WriteLine("Graag hier je wachtwoord invullen:"); + Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter, 1 kleine letter en 1 cijfer"); password = Console.ReadLine()!; - } while (string.IsNullOrWhiteSpace(password)); + } while (ValidationLogic.IsValidPassword(password) != true); do { - Console.Write("Volledige naam: "); + Console.WriteLine("Graag hier je volledige naam invullen:"); + Console.WriteLine("De juiste syntax is minimaal 1 letter lang en bevat geen nummers"); fullName = Console.ReadLine()!; - } while (string.IsNullOrWhiteSpace(fullName)); + } while (ValidationLogic.IsValidFullname(fullName) != true); // create new employee object AccountModel newEmployee = new AccountModel( diff --git a/Presentation/UserRegistration.cs b/Presentation/UserRegistration.cs index e74d71f..f19e931 100644 --- a/Presentation/UserRegistration.cs +++ b/Presentation/UserRegistration.cs @@ -6,63 +6,63 @@ namespace Project_B.Logic; static class UserRegistration { - static private AccountsLogic accountsLogic = new AccountsLogic(); - private const int Level = 0; + static private AccountsLogic accountsLogic = new AccountsLogic(); + private const int Level = 0; - public static void Start() - { - Console.WriteLine("Welkom bij de registratiepagina"); - Console.WriteLine("[1] terug naar het startmenu"); - - string Email; - do + public static void Start() { - do - { - Console.WriteLine("Graag hier je email invullen:"); - Email = Console.ReadLine().ToLower(); - } while ( ValidationLogic.IsValidEmail(Email) != true && Email != "1"); + Console.WriteLine("Welkom bij de registratiepagina"); + Console.WriteLine("[1] terug naar het startmenu"); - if (Email == "1") - { - Menu.Start(); - return; - } - } while (Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$") != true); + string? Email; + do + { + do + { + Console.WriteLine("Graag hier je email invullen:"); + Email = Console.ReadLine()!.ToLower(); + } while (ValidationLogic.IsValidEmail(Email) != true && Email != "1"); - string? Password; - do - { - Console.WriteLine("Graag hier je wachtwoord invullen:"); - Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter, 1 kleine letter en 1 cijfer"); - Password = Console.ReadLine(); + if (Email == "1") + { + Menu.Start(); + return; + } + } while (Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$") != true); - } while (ValidationLogic.IsValidPassword(Password) != true); + string? Password; + do + { + Console.WriteLine("Graag hier je wachtwoord invullen:"); + Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter, 1 kleine letter en 1 cijfer"); + Password = Console.ReadLine()!; - string FullName; - do - { - Console.WriteLine("Graag hier je volledige naam invullen:"); - Console.WriteLine("De juiste syntax is minimaal 1 letter lang en bevat geen nummers"); - FullName = Console.ReadLine(); - } while (ValidationLogic.IsValidFullname(FullName) != true); + } while (ValidationLogic.IsValidPassword(Password) != true); - AccountModel? acc = accountsLogic.CheckRegistration(Email); - if (acc == null) - { - AccountModel newAcc = new AccountModel(accountsLogic.GetLastID() + 1, Email, Password, FullName, Level); - accountsLogic.UpdateList(newAcc); + string FullName; + do + { + Console.WriteLine("Graag hier je volledige naam invullen:"); + Console.WriteLine("De juiste syntax is minimaal 1 letter lang en bevat geen nummers"); + FullName = Console.ReadLine()!; + } while (ValidationLogic.IsValidFullname(FullName) != true); - Console.WriteLine("Je gegevens zijn opgeslagen, u kunt nu inloggen met uw account."); - } - else - { - Console.WriteLine("De email die u heeft ingevuld is al gekoppeld aan een account."); - Console.WriteLine("Probeer het opnieuw."); - Start(); - } + AccountModel? acc = accountsLogic.CheckRegistration(Email); + if (acc == null) + { + AccountModel newAcc = new AccountModel(accountsLogic.GetLastID() + 1, Email, Password, FullName, Level); + accountsLogic.UpdateList(newAcc); + + Console.WriteLine("Je gegevens zijn opgeslagen, u kunt nu inloggen met uw account."); + } + else + { + Console.WriteLine("De email die u heeft ingevuld is al gekoppeld aan een account."); + Console.WriteLine("Probeer het opnieuw."); + Start(); + } - Menu.Start(); - } + Menu.Start(); + } } \ No newline at end of file From 72899deeaf53aa706cb540824477b9d9655b9dc6 Mon Sep 17 00:00:00 2001 From: joelhogeschool <1062069@hr.nl> Date: Tue, 13 Jun 2023 13:29:41 +0200 Subject: [PATCH 54/63] added interface interface for all accounts --- DataModels/AccountModel.cs | 2 +- DataModels/Customer.cs | 2 +- DataModels/Employee.cs | 2 +- DataModels/IAccounts.cs | 19 +++++++++++++++++++ DataModels/Manager.cs | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 DataModels/IAccounts.cs diff --git a/DataModels/AccountModel.cs b/DataModels/AccountModel.cs index 997b11d..78a1665 100644 --- a/DataModels/AccountModel.cs +++ b/DataModels/AccountModel.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -class AccountModel +class AccountModel: IAccount { [JsonPropertyName("id")] public int Id { get; set; } diff --git a/DataModels/Customer.cs b/DataModels/Customer.cs index 3d31769..e056723 100644 --- a/DataModels/Customer.cs +++ b/DataModels/Customer.cs @@ -1,4 +1,4 @@ -class Customer : AccountModel +class Customer : AccountModel, IAccount { public Customer(int id, string emailAddress, string password, string fullName, int level) : base(id, emailAddress, password, fullName, level) diff --git a/DataModels/Employee.cs b/DataModels/Employee.cs index bb5de03..df2f204 100644 --- a/DataModels/Employee.cs +++ b/DataModels/Employee.cs @@ -1,4 +1,4 @@ -class Employee : AccountModel +class Employee : AccountModel, IAccount { public Employee(int id, string emailAddress, string password, string fullName, int level) : base(id, emailAddress, password, fullName, level) diff --git a/DataModels/IAccounts.cs b/DataModels/IAccounts.cs new file mode 100644 index 0000000..f3d30b9 --- /dev/null +++ b/DataModels/IAccounts.cs @@ -0,0 +1,19 @@ +using System.Text.Json.Serialization; + +interface IAccount +{ + [JsonPropertyName("id")] + int Id { get; set; } + + [JsonPropertyName("emailAddress")] + string EmailAddress { get; set; } + + [JsonPropertyName("password")] + string Password { get; set; } + + [JsonPropertyName("fullName")] + string FullName { get; set; } + + [JsonPropertyName("level")] + int Level { get; set; } +} \ No newline at end of file diff --git a/DataModels/Manager.cs b/DataModels/Manager.cs index 35f7f9b..ab9014e 100644 --- a/DataModels/Manager.cs +++ b/DataModels/Manager.cs @@ -1,4 +1,4 @@ -class Manager : AccountModel +class Manager : AccountModel, IAccount { public Manager(int id, string emailAddress, string password, string fullName, int level) : base(id, emailAddress, password, fullName, level) From 07b0c3c5572d3bd9d5e9ef859718be55fb588413 Mon Sep 17 00:00:00 2001 From: Jimmy-Tran Date: Tue, 13 Jun 2023 13:31:04 +0200 Subject: [PATCH 55/63] Fixed reservation view --- DataSources/reservations.json | 40 +++++++------- Logic/TableLogic.cs | 26 +++++----- .../Reservation/ReservationConsole.cs | 8 +-- Presentation/Reservation/ReservationView.cs | 52 ++++++++++++------- 4 files changed, 68 insertions(+), 58 deletions(-) diff --git a/DataSources/reservations.json b/DataSources/reservations.json index c6ab7ec..56847db 100644 --- a/DataSources/reservations.json +++ b/DataSources/reservations.json @@ -1,12 +1,12 @@ [ { "ID": 1, - "ClientNumber": 9, - "Name": "Henno Passchier", - "Email": "henno.passchier@gmail.com", - "Date": "2023-05-26T00:00:00", - "ReservationCode": "XF3S7M", - "TimeSlot": "20:00:00", + "ClientNumber": 0, + "Name": "12-09", + "Email": "adadam@gmail.com", + "Date": "2023-12-09T00:00:00", + "ReservationCode": "RL6S8P", + "TimeSlot": "16:00:00", "Tables": [ "1" ], @@ -17,29 +17,25 @@ { "ID": 2, "ClientNumber": 0, - "Name": "Jimmy Tran", - "Email": "jimmy.trxn@gmail.com", - "Date": "2024-12-05T00:00:00", - "ReservationCode": "UH5C8S", - "TimeSlot": "18:00:00", - "Tables": [ - "4D" - ], - "Amt_People": 4, + "Name": "jeffrey", + "Email": "jeffrey@het.com", + "Date": "2023-12-09T00:00:00", + "ReservationCode": "PM8H3K", + "TimeSlot": "16:00:00", + "Tables": [], + "Amt_People": 2, "CourseMenu": null, "Verified": false }, { "ID": 3, "ClientNumber": 0, - "Name": "test test", - "Email": "test@test.nl", - "Date": "2023-06-07T00:00:00", - "ReservationCode": "GK2U8E", + "Name": "dkkda", + "Email": "daa@dada.co", + "Date": "2023-12-09T00:00:00", + "ReservationCode": "WA2F7M", "TimeSlot": "16:00:00", - "Tables": [ - "1" - ], + "Tables": [], "Amt_People": 2, "CourseMenu": null, "Verified": false diff --git a/Logic/TableLogic.cs b/Logic/TableLogic.cs index 03637f9..fd29f2b 100644 --- a/Logic/TableLogic.cs +++ b/Logic/TableLogic.cs @@ -11,23 +11,25 @@ namespace Project_B.Logic public static class TableLogic { - public static List AvailableTables = new List { "6A", "6B", "4A", "4B", "4C", "4D", "4E", "1", "2", "3", "4", "5", "6", "7", "8", "A", "B", "C", "D", "E", "F", "G", "H" }; + public static List AvailableTables = new List { "_6A", "_6B", "_4A", "_4B", "_4C", "_4D", "_4E", "_1", "_2", "_3", "_4", "_5", "_6", "_7", "_8", "A", "B", "C", "D", "E", "F", "G", "H" }; public static List CheckTables(DateTime date, TimeSpan timeslot, int persons) { List res = ReservationLogic.GetReservations(); //Get the reservations in an object and loop throught it - if (res != null) - { - foreach (ReservationModel reservartion in res) - { - if (reservartion.Date == date && reservartion.TimeSlot == timeslot) - { //Only select the reservation that are given by Date/Time - if (reservartion.Tables != null) - { //Check if the reservation has tablenumbers in it + if (res != null) { + + foreach (ReservationModel reservartion in res) { + Console.WriteLine($"{reservartion.Date} {date} {reservartion.TimeSlot} {timeslot}"); + + if (reservartion.Date == date && reservartion.TimeSlot == timeslot) { + Console.WriteLine("Found a match"); + //Only select the reservation that are given by Date/Time + if (reservartion.Tables != null) { //Check if the reservation has tablenumbers in it foreach (string i in reservartion.Tables) { - AvailableTables.Remove($"{i}"); //Remove the tablenumber from the available table list + Console.WriteLine(i + "huh"); + AvailableTables.Remove($"_{i}"); //Remove the tablenumber from the available table list } } @@ -40,11 +42,11 @@ public static List CheckTables(DateTime date, TimeSpan timeslot, int per if (persons == 6 || persons == 5) { - AvailableTables = AvailableTables.Where(table => table.StartsWith("6") && table.Length == 3).ToList(); + AvailableTables = AvailableTables.Where(table => table.StartsWith("_6") && table.Length == 3).ToList(); } else if (persons == 4 || persons == 3) { - AvailableTables = AvailableTables.Where(table => table.StartsWith("4") && table.Length == 3).ToList(); + AvailableTables = AvailableTables.Where(table => table.StartsWith("_4") && table.Length == 3).ToList(); } else if (persons == 2) { diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 2e0918c..8b012c9 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -186,11 +186,11 @@ public void Reserveren() { Console.WriteLine("Welke tafel wilt u? (bijv. 4E of 2)"); tableCheck = Console.ReadLine(); - } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"{tableCheck.ToUpper()}")); + } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"_{tableCheck.ToUpper()}")); id = ReservationLogic.GetLastID() + 1; - if (TableLogic.TableChecker($"{tableCheck.ToUpper()}")) + if (TableLogic.TableChecker($"_{tableCheck.ToUpper()}")) { tables.Add(tableCheck); try @@ -343,11 +343,11 @@ public void Reserveren(int client_id, string username) { Console.WriteLine("Welke tafel wilt u? (bijv. 4E of 2)"); tableCheck = Console.ReadLine(); - } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"{tableCheck.ToUpper()}")); + } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"_{tableCheck.ToUpper()}")); id = ReservationLogic.GetLastID() + 1; - if (TableLogic.TableChecker($"{tableCheck.ToUpper()}")) + if (TableLogic.TableChecker($"_{tableCheck.ToUpper()}")) { tables.Add(tableCheck); try diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 9e31838..04639f9 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -4,6 +4,7 @@ public class Reservation { + static private AccountsLogic accountsLogic = new AccountsLogic(); static public void DisplayReservation() @@ -106,31 +107,42 @@ static public void MakeReservation() List AvailableTables = TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Amt_People); - Console.WriteLine($"Tafelnummers beschikbaar: " + string.Join(", ", AvailableTables)); + - Console.WriteLine("Tafel nummers (klaar ENTER)"); - List Tables = new List(); - while (true) - { - string Table_number = Console.ReadLine(); + TimeSpan tempTime; - // Keep looping until user pressed ENTER, only numeric - if (Table_number != "") - { - try - { - Tables.Add(Table_number); - } - catch - { - Console.WriteLine("Toevoegen mislukt, voer tafel nummers in!"); - } + TimeSpan.TryParse(TimeSlot, out tempTime); + + DateTime tempDate; + DateTime.TryParse(Date, out tempDate); + + ReservationLogic.ShowTablesAvailability(tempDate, tempTime, Amt_People); + + List CorrectedTables = new List(); + foreach(string table in AvailableTables) { + if(table.Length > 1) { + string tableCorrect; + tableCorrect = table.Remove(0,1); + CorrectedTables.Add(tableCorrect); } - else - { - break; + else { + CorrectedTables.Add(table); } + } + + Console.WriteLine($"Tafelnummers beschikbaar: " + string.Join(", ", CorrectedTables)); + Console.WriteLine("Schrijf de tafel nummer?"); + List Tables = new List(); + bool TableChecker = true; + string TableNumber = Console.ReadLine(); + while(TableChecker is true){ + if (CorrectedTables.Contains(TableNumber)) { + TableChecker = false; + } else { + Console.WriteLine("Graag een geldige tafel nummer typen."); + TableNumber = Console.ReadLine(); + } } From 507af44a90f12035eefd6db84fc724d26739f1a4 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 13 Jun 2023 14:00:58 +0200 Subject: [PATCH 56/63] nullable voor alles verwijderd --- Logic/ReservationLogic.cs | 34 ++-- Presentation/Mederwerker.cs | 4 +- Presentation/Reservation/MyReservation.cs | 148 +++++++++++------- .../Reservation/ReservationConsole.cs | 42 ++--- Presentation/Reservation/ReservationView.cs | 63 ++++---- 5 files changed, 168 insertions(+), 123 deletions(-) diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index 98a3bbf..3f5a1b4 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -58,6 +58,7 @@ public static bool AddReservation(int _id, int _clientnumber, string _name, stri } catch (Exception ex) { // Catch the error and return false + Console.WriteLine(ex); return false; } } @@ -68,12 +69,13 @@ public static List GetReservations() { //Try to get the reservations and convert them into a list string jsonContent = File.ReadAllText(@"DataSources/reservations.json"); - List reservations = JsonConvert.DeserializeObject>(jsonContent); - return reservations.Count > 0 ? reservations : new List(); + List? reservations = JsonConvert.DeserializeObject>(jsonContent); + return reservations?.Count > 0 ? reservations : new List(); } catch (Exception ex) { + Console.WriteLine(ex); // Console.WriteLine($"Error: {ex.Message}"); } return new List(); @@ -88,11 +90,13 @@ public static List GetReservations(string _Searchterm) List reservations = GetReservations(); //Loop through the list and get the reservation by the given searchterm - - foreach (ReservationModel reservation in reservations) { - if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm || reservation.ReservationCode == _Searchterm) { + + foreach (ReservationModel reservation in reservations) + { + if (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _Searchterm || reservation.ReservationCode == _Searchterm) + { ResList.Add(reservation); //Return the reservation - } + } } return ResList; //Return nothing if nothing came out } @@ -103,15 +107,19 @@ public static List GetReservations(string _Searchterm) return new List(); } - public static List GetReservations(int clientnumber) { + public static List GetReservations(int clientnumber) + { List ResList = new(); - try { + try + { //Get reservations from other function List reservations = GetReservations(); //Loop through the list and get the reservation by the given searchterm - foreach (ReservationModel reservation in reservations) { - if (reservation.ClientNumber == clientnumber) { + foreach (ReservationModel reservation in reservations) + { + if (reservation.ClientNumber == clientnumber) + { ResList.Add(reservation); //Return the reservation } } @@ -124,7 +132,7 @@ public static List GetReservations(int clientnumber) { return new List(); } - public static ReservationModel GetReservation(string _Searchterm) + public static ReservationModel? GetReservation(string _Searchterm) { try { @@ -141,10 +149,12 @@ public static ReservationModel GetReservation(string _Searchterm) return reservation; //Return the reservation } } - return null; //Return nothing if nothing came out + //Return nothing if nothing came out + return null; } catch (Exception ex) { + Console.WriteLine(ex); return null; } } diff --git a/Presentation/Mederwerker.cs b/Presentation/Mederwerker.cs index 27c9330..10ad1cf 100644 --- a/Presentation/Mederwerker.cs +++ b/Presentation/Mederwerker.cs @@ -50,14 +50,14 @@ public static void Mederwerker_gegevens(string username, int id) do { - Console.WriteLine("Graag hier je wachtwoord invullen:"); + Console.WriteLine("Graag hier de wachtwoord invullen:"); Console.WriteLine("De juiste syntax is minimaal 6 tekens lang, 1 hoofdletter, 1 kleine letter en 1 cijfer"); password = Console.ReadLine()!; } while (ValidationLogic.IsValidPassword(password) != true); do { - Console.WriteLine("Graag hier je volledige naam invullen:"); + Console.WriteLine("Graag hier de volledige naam invullen:"); Console.WriteLine("De juiste syntax is minimaal 1 letter lang en bevat geen nummers"); fullName = Console.ReadLine()!; } while (ValidationLogic.IsValidFullname(fullName) != true); diff --git a/Presentation/Reservation/MyReservation.cs b/Presentation/Reservation/MyReservation.cs index 7d1814c..e7476b3 100644 --- a/Presentation/Reservation/MyReservation.cs +++ b/Presentation/Reservation/MyReservation.cs @@ -2,66 +2,81 @@ using Project_B.Logic; using Project_B.DataModels; using System.Threading; -using Project_B.Logic; - -public class MyReservation { +public class MyReservation +{ static private AccountsLogic accountsLogic = new AccountsLogic(); - public static string GetReservationCode() { + public static string GetReservationCode() + { string ReservationCode; - do { + do + { Console.WriteLine($"Vul uw reserveringscode in. (6 Karakters)"); - ReservationCode = Console.ReadLine(); + ReservationCode = Console.ReadLine()!; } while (ReservationCode.Length != 6); - return ReservationCode; } - public static string GetReservationCode(string username, int id) { - try { + public static string GetReservationCode(string username, int id) + { + try + { //Try to find the reservation code by the id of the user. When it does not excist it will return a empty string List reservations = ReservationLogic.GetReservations(id); - string ReservationCode; + string ReservationCode = ""; - if (reservations.Count > 1) { - List r_choices = new List {}; - foreach (ReservationModel reservation in reservations) { + if (reservations.Count > 1) + { + List r_choices = new List { }; + foreach (ReservationModel reservation in reservations) + { r_choices.Add($"[{reservation.ID}] {reservation.ToString()}"); } string[] Array_r_choices = r_choices.ToArray(); - int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] {$"Er zijn meerdere reserveringen gevonden onder uw naam", "Kies de juiste reservering"}, Array_r_choices); - + int selectedClass = MenuLogic.MultipleChoice(true, "", 1, new string[] { $"Er zijn meerdere reserveringen gevonden onder uw naam", "Kies de juiste reservering" }, Array_r_choices); + int r_id = Convert.ToInt32(Array_r_choices[selectedClass].Split("]")[0].Remove(0, 1)); Console.WriteLine(r_id); - ReservationCode = reservations.Find(x => x.ID == r_id).ReservationCode; - } else { - ReservationCode = reservations.Find(x => x.ClientNumber == id).ReservationCode; + ReservationModel? foundReservation = reservations.Find(x => x.ID == r_id); + ReservationCode = foundReservation?.ReservationCode ?? ""; + } + else + { + ReservationModel? foundReservation = reservations.Find(x => x.ClientNumber == id); + ReservationCode = foundReservation?.ReservationCode ?? ""; } Console.WriteLine(ReservationCode); return ReservationCode; - } catch (Exception e) { + } + catch (Exception e) + { Console.WriteLine(e); return ""; } - + } - static public void ShowReservationInfo(string _ReservationCode) { - + static public void ShowReservationInfo(string _ReservationCode) + { + List reservations = ReservationLogic.GetReservations(); bool Found = false; - foreach (ReservationModel reservation in reservations) { - if (reservation.ReservationCode == _ReservationCode) { //Search in the list if the Code excist + foreach (ReservationModel reservation in reservations) + { + if (reservation.ReservationCode == _ReservationCode) + { //Search in the list if the Code excist Found = true; // set Found to true so it wont show NotFound - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] {"Reservatie Informatie:", $"Datum: {reservation.Date.ToString("dddd, dd MMMM yyyy")}", $"Tijd: {reservation.TimeSlot.ToString(@"hh\:mm")}", $"Reserverings Code: {reservation.ReservationCode}"}, "Bevestig reservering", "Annuleer reservering", "Terug"); + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { "Reservatie Informatie:", $"Datum: {reservation.Date.ToString("dddd, dd MMMM yyyy")}", $"Tijd: {reservation.TimeSlot.ToString(@"hh\:mm")}", $"Reserverings Code: {reservation.ReservationCode}" }, "Bevestig reservering", "Annuleer reservering", "Terug"); - switch (selectedClass) { + switch (selectedClass) + { case 0: - if (reservation.Verified == true) { //Check if the field is true + if (reservation.Verified == true) + { //Check if the field is true Console.WriteLine("Reservering is al bevestigd! \nDruk op iets om door te gaan..."); Console.ReadKey(); @@ -69,12 +84,14 @@ static public void ShowReservationInfo(string _ReservationCode) { break; } ConsoleKey Confirmed; - do { + do + { Console.WriteLine($"Druk op 'ENTER' om de reservering te bevestigen... (Terug? druk op 'backspace')"); //Let the user press ENTER to confirm the reservation or backspace to cancel Confirmed = Console.ReadKey(true).Key; } while (Confirmed != ConsoleKey.Enter && Confirmed != ConsoleKey.Backspace); - switch (Confirmed) { + switch (Confirmed) + { case ConsoleKey.Enter: reservation.Verified = true; @@ -95,22 +112,27 @@ static public void ShowReservationInfo(string _ReservationCode) { } break; case 1: - - do { + + do + { Console.WriteLine($"Weet u zeker dat de reservering geannuleerd wordt? \nDruk op 'ENTER' om de reservering te annuleren... (Terug? druk op 'backspace')"); Confirmed = Console.ReadKey(true).Key; } while (Confirmed != ConsoleKey.Enter && Confirmed != ConsoleKey.Backspace); - switch (Confirmed) { + switch (Confirmed) + { case ConsoleKey.Enter: - try { + try + { ReservationLogic.DeleteReservation(reservation.ID); Console.WriteLine("Annuleren gelukt! \nDruk op iets om door te gaan..."); Console.ReadKey(); Menu.Start(); - } catch { - + } + catch + { + } break; case ConsoleKey.Backspace: @@ -126,34 +148,40 @@ static public void ShowReservationInfo(string _ReservationCode) { default: Menu.Start(); break; - } } } + } - if (Found != true) { + if (Found != true) + { Console.WriteLine("\nGeen reservering gevonden, heeft u de juiste code ingevoerd?\nDruk op iets om door te gaan..."); Console.ReadKey(); Menu.Start(); } - + } //Overloading the functions for logged in users - static public void ShowReservationInfo(string username, int id, string _ReservationCode) { - + static public void ShowReservationInfo(string username, int id, string _ReservationCode) + { + List reservations = ReservationLogic.GetReservations(); bool Found = false; - foreach (ReservationModel reservation in reservations) { - if (reservation.ReservationCode == _ReservationCode) { //Search in the list if the Code excist + foreach (ReservationModel reservation in reservations) + { + if (reservation.ReservationCode == _ReservationCode) + { //Search in the list if the Code excist Found = true; // set Found to true so it wont show NotFound - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] {"Reservatie Informatie:", $"Datum: {reservation.Date.ToString("dddd, dd MMMM yyyy")}", $"Tijd: {reservation.TimeSlot.ToString(@"hh\:mm")}", $"Reserverings Code: {reservation.ReservationCode}"}, "Bevestig reservering", "Annuleer reservering", "Terug"); + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { "Reservatie Informatie:", $"Datum: {reservation.Date.ToString("dddd, dd MMMM yyyy")}", $"Tijd: {reservation.TimeSlot.ToString(@"hh\:mm")}", $"Reserverings Code: {reservation.ReservationCode}" }, "Bevestig reservering", "Annuleer reservering", "Terug"); - switch (selectedClass) { + switch (selectedClass) + { case 0: - if (reservation.Verified == true) { //Check if the field is true + if (reservation.Verified == true) + { //Check if the field is true Console.WriteLine("Reservering is al bevestigd! \nDruk op iets om door te gaan..."); Console.ReadKey(); @@ -161,12 +189,14 @@ static public void ShowReservationInfo(string username, int id, string _Reservat break; } ConsoleKey Confirmed; - do { + do + { Console.WriteLine($"Druk op 'ENTER' om de reservering te bevestigen... (Terug? druk op 'backspace')"); //Let the user press ENTER to confirm the reservation or backspace to cancel Confirmed = Console.ReadKey(true).Key; } while (Confirmed != ConsoleKey.Enter && Confirmed != ConsoleKey.Backspace); - switch (Confirmed) { + switch (Confirmed) + { case ConsoleKey.Enter: reservation.Verified = true; @@ -187,22 +217,27 @@ static public void ShowReservationInfo(string username, int id, string _Reservat } break; case 1: - - do { + + do + { Console.WriteLine($"Weet u zeker dat de reservering geannuleerd wordt? \nDruk op 'ENTER' om de reservering te annuleren... (Terug? druk op 'backspace')"); Confirmed = Console.ReadKey(true).Key; } while (Confirmed != ConsoleKey.Enter && Confirmed != ConsoleKey.Backspace); - switch (Confirmed) { + switch (Confirmed) + { case ConsoleKey.Enter: - try { + try + { ReservationLogic.DeleteReservation(reservation.ID); Console.WriteLine("Annuleren gelukt! \nDruk op iets om door te gaan..."); Console.ReadKey(); CustomerMenu.Start(username, id); - } catch { - + } + catch + { + } break; case ConsoleKey.Backspace: @@ -218,16 +253,17 @@ static public void ShowReservationInfo(string username, int id, string _Reservat default: Menu.Start(); break; - } } } + } - if (Found != true) { + if (Found != true) + { Console.WriteLine("\nGeen reservering gevonden\nDruk op iets om door te gaan..."); Console.ReadKey(); CustomerMenu.Start(username, id); } - + } } \ No newline at end of file diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index 78a8f2a..a35f1e1 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -23,7 +23,7 @@ class ReservationConsole public List tables = new List(); bool reserveValid = true; - public string phoneNumber { get; set; } + public string? phoneNumber { get; set; } public void Reserveren() { @@ -32,7 +32,7 @@ public void Reserveren() do { Console.WriteLine("Wat is uw voornaam en achternaam?"); - nameCheck = Console.ReadLine(); + nameCheck = Console.ReadLine()!; } while (nameCheck.Length <= 3); // Change class propperty to given variable after conditions are correct @@ -46,8 +46,7 @@ public void Reserveren() do { Console.WriteLine("(Optioneel) Wat is uw telefoon nummer? (+31612345678 or 0612345678)"); - phoneCheck = Console.ReadLine(); - + phoneCheck = Console.ReadLine()!; if (!Regex.IsMatch(phoneCheck, phonePattern)) { @@ -62,7 +61,7 @@ public void Reserveren() do { Console.WriteLine("Wat is uw email adres? (bijv. John.Doe@gmail.com)"); - emailCheck = Console.ReadLine().ToLower(); + emailCheck = Console.ReadLine()!.ToLower(); } while (ValidationLogic.IsValidEmail(emailCheck) != true); // Will return an error message if not correct. email = emailCheck; @@ -74,7 +73,7 @@ public void Reserveren() do { Console.WriteLine("Hoeveel mensen zullen er zijn inclusief u?"); - string input = Console.ReadLine(); + string input = Console.ReadLine()!; if (int.TryParse(input, out amountPeopleCheck) && amountPeopleCheck > 0) { @@ -103,7 +102,6 @@ public void Reserveren() Console.WriteLine("Hoeveel mensen zullen er zijn inclusief u?"); amountPeopleCheck = Convert.ToInt32(Console.ReadLine()); } while (ValidationLogic.AmtPeopleCheck(amountPeopleCheck) != true); // Let the user pick the amount of people again with the validation of 6 or under. - amt_people = amountPeopleCheck; break; default: @@ -127,7 +125,7 @@ public void Reserveren() do { Console.WriteLine("Welke datum wilt u reserveren? (DD-MM-JJJJ):"); - DateCheck = Console.ReadLine(); + DateCheck = Console.ReadLine()!; } while (ValidationLogic.IsValidDate(DateCheck) != true); if (DateTime.Parse(DateCheck) < DateTime.Today) @@ -142,7 +140,7 @@ public void Reserveren() date = DateTime.Parse(DateCheck); - string TimeSlotCheck; + string TimeSlotCheck = ""; do { int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { $"{date.ToString("dddd, dd MMMM yyyy")}", "Selecteer een tijdslot:" }, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); @@ -158,9 +156,6 @@ public void Reserveren() case 2: TimeSlotCheck = "20:00"; break; - default: - TimeSlotCheck = null; - break; } } while (ValidationLogic.IsValidTime(TimeSlotCheck) != true); timeslot = TimeSpan.Parse(TimeSlotCheck); @@ -185,7 +180,7 @@ public void Reserveren() do { Console.WriteLine("Welke tafel wilt u? (bijv. 4E of 2)"); - tableCheck = Console.ReadLine(); + tableCheck = Console.ReadLine()!; } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"_{tableCheck.ToUpper()}")); id = ReservationLogic.GetLastID() + 1; @@ -220,9 +215,9 @@ public void Reserveren(int client_id, string username) clientnumber = client_id; name = username; AccountsLogic AccountData = new AccountsLogic(); - AccountModel AccountResult = AccountData.GetById(client_id); + AccountModel? AccountResult = AccountData.GetById(client_id); - email = AccountResult.EmailAddress; + email = AccountResult?.EmailAddress; int amountPeopleCheck; bool isValidAmount = false; @@ -230,7 +225,7 @@ public void Reserveren(int client_id, string username) do { Console.WriteLine("Hoeveel mensen zullen er zijn inclusief u?"); - string input = Console.ReadLine(); + string input = Console.ReadLine()!; if (int.TryParse(input, out amountPeopleCheck) && amountPeopleCheck > 0) { @@ -284,7 +279,7 @@ public void Reserveren(int client_id, string username) do { Console.WriteLine("Welke datum wilt u reserveren? (DD-MM-JJJJ):"); - DateCheck = Console.ReadLine(); + DateCheck = Console.ReadLine()!; } while (ValidationLogic.IsValidDate(DateCheck) != true); if (DateTime.Parse(DateCheck) < DateTime.Today) @@ -299,7 +294,7 @@ public void Reserveren(int client_id, string username) date = DateTime.Parse(DateCheck); - string TimeSlotCheck; + string TimeSlotCheck = ""; do { int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { $"{date.ToString("dddd, dd MMMM yyyy")}", "Selecteer een tijdslot:" }, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); @@ -315,9 +310,6 @@ public void Reserveren(int client_id, string username) case 2: TimeSlotCheck = "20:00"; break; - default: - TimeSlotCheck = null; - break; } } while (ValidationLogic.IsValidTime(TimeSlotCheck) != true); timeslot = TimeSpan.Parse(TimeSlotCheck); @@ -342,7 +334,7 @@ public void Reserveren(int client_id, string username) do { Console.WriteLine("Welke tafel wilt u? (bijv. 4E of 2)"); - tableCheck = Console.ReadLine(); + tableCheck = Console.ReadLine()!; } while (!TableLogic.CheckTables(date, timeslot, amt_people).Contains($"_{tableCheck.ToUpper()}")); id = ReservationLogic.GetLastID() + 1; @@ -352,9 +344,9 @@ public void Reserveren(int client_id, string username) tables.Add(tableCheck); try { - ReservationLogic.AddReservation(id, clientnumber, name, email, date, reservationcode, timeslot, tables, amt_people); + ReservationLogic.AddReservation(id, clientnumber, name, email!, date, reservationcode, timeslot, tables, amt_people); Console.WriteLine("Gelukt!"); - EmailFunction.sendmail(email, name, reservationcode, date, timeslot); + EmailFunction.sendmail(email!, name, reservationcode, date, timeslot); EmailFunction.warning(); // console read en dan terug naar de ingelogde scherm Console.WriteLine("druk op een toets om terug te gaan naar de menu"); @@ -363,7 +355,7 @@ public void Reserveren(int client_id, string username) } catch (Exception e) { - Console.WriteLine("Niet Gelukt!"); + Console.WriteLine(e); return; } diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 9b7deaa..9aa4a50 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -5,7 +5,7 @@ public class Reservation { - + static private AccountsLogic accountsLogic = new AccountsLogic(); static public void DisplayReservation() @@ -33,7 +33,7 @@ static public void MakeReservation() do { Console.Write("Heeft de klant een account? (J/N): "); - HasAccount = Console.ReadLine().ToUpper(); + HasAccount = Console.ReadLine()!.ToUpper(); } while (HasAccount != "J" && HasAccount != "N"); string ClientNumber = "0"; @@ -47,21 +47,21 @@ static public void MakeReservation() do { Console.Write("Zoeken naar account (Email): "); - SearchTerm = Console.ReadLine().ToLower(); + SearchTerm = Console.ReadLine()!.ToLower(); } while (SearchTerm.Length == 0); try { - AccountModel AccountData = accountsLogic.GetByEmail(SearchTerm); + AccountModel? AccountData = accountsLogic.GetByEmail(SearchTerm); - ClientNumber = Convert.ToString(AccountData.Id); + ClientNumber = Convert.ToString(AccountData!.Id); Name = AccountData.FullName; Email = AccountData.EmailAddress; } catch (Exception e) { - Console.WriteLine("Account niet gevonden!"); + Console.WriteLine(e); HasAccount = "N"; } @@ -72,14 +72,14 @@ static public void MakeReservation() do { Console.Write("Naam: "); - Name = Console.ReadLine(); + Name = Console.ReadLine()!; } while (Name.Length <= 3); do { Console.Write("Email: "); - Email = Console.ReadLine(); + Email = Console.ReadLine()!; } while (ValidationLogic.IsValidEmail(Email) != true); } @@ -111,7 +111,7 @@ static public void MakeReservation() do { Console.Write("Time (00:00): "); - TimeSlot = Console.ReadLine(); + TimeSlot = Console.ReadLine()!; } while (ValidationLogic.IsValidTime(TimeSlot) != true); @@ -124,7 +124,7 @@ static public void MakeReservation() List AvailableTables = TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Amt_People); - + TimeSpan tempTime; @@ -136,29 +136,36 @@ static public void MakeReservation() ReservationLogic.ShowTablesAvailability(tempDate, tempTime, Amt_People); List CorrectedTables = new List(); - foreach(string table in AvailableTables) { - if(table.Length > 1) { + foreach (string table in AvailableTables) + { + if (table.Length > 1) + { string tableCorrect; - tableCorrect = table.Remove(0,1); + tableCorrect = table.Remove(0, 1); CorrectedTables.Add(tableCorrect); } - else { + else + { CorrectedTables.Add(table); } } - + Console.WriteLine($"Tafelnummers beschikbaar: " + string.Join(", ", CorrectedTables)); Console.WriteLine("Schrijf de tafel nummer?"); List Tables = new List(); bool TableChecker = true; - string TableNumber = Console.ReadLine(); - while(TableChecker is true){ - if (CorrectedTables.Contains(TableNumber)) { + string TableNumber = Console.ReadLine()!; + while (TableChecker is true) + { + if (CorrectedTables.Contains(TableNumber)) + { TableChecker = false; - } else { + } + else + { Console.WriteLine("Graag een geldige tafel nummer typen."); - TableNumber = Console.ReadLine(); + TableNumber = Console.ReadLine()!; } } @@ -181,7 +188,7 @@ static public void MakeReservation() static public void ChangeReservation() { Console.Write("Zoeken (ID / Naam / Email / Reservering Code): "); - string Searchterm = Console.ReadLine(); + string Searchterm = Console.ReadLine()!; List r = ReservationLogic.GetReservations(Searchterm); @@ -207,14 +214,14 @@ static public void ChangeReservation() do { Console.Write("Naam: "); - Name = Console.ReadLine(); + Name = Console.ReadLine()!; } while (Name.Length <= 3); string Email; do { Console.Write("Email: "); - Email = Console.ReadLine(); + Email = Console.ReadLine()!; } while (ValidationLogic.IsValidEmail(Email) != true); string Date; @@ -245,14 +252,14 @@ static public void ChangeReservation() do { Console.Write("Time (00:00): "); - TimeSlot = Console.ReadLine(); + TimeSlot = Console.ReadLine()!; } while (ValidationLogic.IsValidTime(TimeSlot) != true); string Amt_People; do { Console.Write("Aantal Personen: "); - Amt_People = Console.ReadLine(); + Amt_People = Console.ReadLine()!; } while (ValidationLogic.IsNumeric(Amt_People) != true); Console.WriteLine("Beschikbare tafels: " + string.Join(", ", TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Convert.ToInt32(Amt_People)))); @@ -260,7 +267,7 @@ static public void ChangeReservation() List Tables = new List(); while (true) { - string Table_number = Console.ReadLine(); + string Table_number = Console.ReadLine()!; if (Table_number != "") { try @@ -302,7 +309,7 @@ public static void DeleteReservationWithID() Console.WriteLine("ID"); int ID = Convert.ToInt32(Console.ReadLine()); - ReservationModel ReservationObject = ReservationLogic.GetReservation(Convert.ToString(ID)); + ReservationModel? ReservationObject = ReservationLogic.GetReservation(Convert.ToString(ID)); if (ReservationObject == null) { @@ -319,7 +326,7 @@ public static void DeleteReservationWithID() do { Console.WriteLine($"(J/N)"); - DeleteObjectbool = Console.ReadLine().ToUpper(); + DeleteObjectbool = Console.ReadLine()!.ToUpper(); } while (DeleteObjectbool != "J" && DeleteObjectbool != "N"); From f36766a04f244ef2ac73d8e802322fb2202f7563 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Tue, 13 Jun 2023 14:44:35 +0200 Subject: [PATCH 57/63] goed getest op reserveren, zou nu okey moeten zijn --- Logic/ReservationLogic.cs | 9 ++++++-- Logic/TableLogic.cs | 21 ++++++++++--------- Presentation/ManagerMenu.cs | 1 - Presentation/Reservation/MyReservation.cs | 4 ++-- .../Reservation/ReservationConsole.cs | 13 ++++++++++++ Presentation/Reservation/ReservationView.cs | 7 ++++++- Presentation/WorkerMenu.cs | 3 +-- 7 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index 3f5a1b4..95b1c99 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -276,8 +276,13 @@ public static void ShowTablesAvailability(DateTime date, TimeSpan timeslot, int else { List TablesList = TableLogic.CheckTables(date, timeslot, persons); - UpdateTableAvailability(TablesList); - ShowTables(); + if (TablesList.Count > 0) + { + UpdateTableAvailability(TablesList); + ShowTables(); + } + + } } diff --git a/Logic/TableLogic.cs b/Logic/TableLogic.cs index fd29f2b..93305d0 100644 --- a/Logic/TableLogic.cs +++ b/Logic/TableLogic.cs @@ -17,18 +17,19 @@ public static class TableLogic public static List CheckTables(DateTime date, TimeSpan timeslot, int persons) { List res = ReservationLogic.GetReservations(); //Get the reservations in an object and loop throught it - if (res != null) { - - foreach (ReservationModel reservartion in res) { - Console.WriteLine($"{reservartion.Date} {date} {reservartion.TimeSlot} {timeslot}"); - - if (reservartion.Date == date && reservartion.TimeSlot == timeslot) { - Console.WriteLine("Found a match"); - //Only select the reservation that are given by Date/Time - if (reservartion.Tables != null) { //Check if the reservation has tablenumbers in it + if (res != null) + { + + foreach (ReservationModel reservartion in res) + { + + if (reservartion.Date == date && reservartion.TimeSlot == timeslot) + { + //Only select the reservation that are given by Date/Time + if (reservartion.Tables != null) + { //Check if the reservation has tablenumbers in it foreach (string i in reservartion.Tables) { - Console.WriteLine(i + "huh"); AvailableTables.Remove($"_{i}"); //Remove the tablenumber from the available table list } } diff --git a/Presentation/ManagerMenu.cs b/Presentation/ManagerMenu.cs index e8317b7..612cc92 100644 --- a/Presentation/ManagerMenu.cs +++ b/Presentation/ManagerMenu.cs @@ -40,7 +40,6 @@ static public void Admin_menu(string username, int id) break; case 1: Reservation.MakeReservation(); - Console.WriteLine("Druk op iets om verder te gaan..."); Console.ReadKey(); Admin_menu(username, id); diff --git a/Presentation/Reservation/MyReservation.cs b/Presentation/Reservation/MyReservation.cs index e7476b3..2c2b51a 100644 --- a/Presentation/Reservation/MyReservation.cs +++ b/Presentation/Reservation/MyReservation.cs @@ -248,10 +248,10 @@ static public void ShowReservationInfo(string username, int id, string _Reservat break; case 2: - Menu.Start(); + CustomerMenu.Start(username, id); break; default: - Menu.Start(); + CustomerMenu.Start(username, id); break; } } diff --git a/Presentation/Reservation/ReservationConsole.cs b/Presentation/Reservation/ReservationConsole.cs index a35f1e1..e834387 100644 --- a/Presentation/Reservation/ReservationConsole.cs +++ b/Presentation/Reservation/ReservationConsole.cs @@ -165,6 +165,12 @@ public void Reserveren() Console.Clear(); Console.WriteLine(date.ToString("dddd, dd MMMM yyyy")); Console.WriteLine(timeslot.ToString(@"hh\:mm")); + if (TableLogic.CheckTables(date, timeslot, amt_people).Count < 1) + { + Console.WriteLine($"Er is geen plek meer voor vandaag probeer een andere dag"); + Console.ReadKey(); + Menu.Start(); + } ReservationLogic.ShowTablesAvailability(date, timeslot, amt_people); Console.WriteLine("email: " + email); @@ -176,6 +182,7 @@ public void Reserveren() reservationcode = text; + string tableCheck; do { @@ -319,6 +326,12 @@ public void Reserveren(int client_id, string username) Console.Clear(); Console.WriteLine(date.ToString("dddd, dd MMMM yyyy")); Console.WriteLine(timeslot.ToString(@"hh\:mm")); + if (TableLogic.CheckTables(date, timeslot, amt_people).Count < 1) + { + Console.WriteLine($"Er is geen plek meer voor vandaag probeer een andere dag"); + Console.ReadKey(); + CustomerMenu.Start(username, client_id); + } ReservationLogic.ShowTablesAvailability(date, timeslot, amt_people); Console.WriteLine("email: " + email); diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 9aa4a50..498429f 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -122,7 +122,12 @@ static public void MakeReservation() Amt_People = Convert.ToInt32(Console.ReadLine()); } while (Amt_People <= 0); - + if (TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Amt_People).Count < 1) + { + Console.WriteLine($"Er is geen plek meer voor vandaag probeer een andere dag"); + Console.ReadKey(); + return; + } List AvailableTables = TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Amt_People); diff --git a/Presentation/WorkerMenu.cs b/Presentation/WorkerMenu.cs index 23998bc..f34745b 100644 --- a/Presentation/WorkerMenu.cs +++ b/Presentation/WorkerMenu.cs @@ -16,8 +16,7 @@ static public void Start(string username, int id) // ingelogd geef parameter's m { // ga naar reserveren waar je een paar optie's weer krijgt // Reservatie res = new Reservatie(); - ReservationConsole res = new ReservationConsole(); - res.Reserveren(); + Reservation.MakeReservation(); Start(username, id); } else if (selectedClass == 2) From 9c998a34120b31b1e807287b5cd6e6f24ee470e0 Mon Sep 17 00:00:00 2001 From: joelhogeschool <124694056+joelhogeschool@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:22:58 +0200 Subject: [PATCH 58/63] Update Mederwerker.cs small change to email verification --- Presentation/Mederwerker.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Presentation/Mederwerker.cs b/Presentation/Mederwerker.cs index 10ad1cf..98637d6 100644 --- a/Presentation/Mederwerker.cs +++ b/Presentation/Mederwerker.cs @@ -42,11 +42,7 @@ public static void Mederwerker_gegevens(string username, int id) { Console.WriteLine("Graag hier de email invullen:"); emailAddress = Console.ReadLine()!.ToLower(); - if (ValidationLogic.IsValidEmail(emailAddress) != true && emailAddress != "1") - { - Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); - } - } while (!Regex.IsMatch(emailAddress, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && emailAddress != "1"); + } while (ValidationLogic.IsValidEmail(emailAddress) != true && emailAddress != "1"); do { @@ -64,11 +60,12 @@ public static void Mederwerker_gegevens(string username, int id) // create new employee object AccountModel newEmployee = new AccountModel( - accountsLogic.GetLastID() + 1, - emailAddress ?? string.Empty, - password ?? string.Empty, - fullName ?? string.Empty, - 2); + accountsLogic.GetLastID() + 1, + emailAddress ?? string.Empty, + password ?? string.Empty, + fullName ?? string.Empty, + 2 + ); // add new employee to accounts accountsLogic.UpdateList(newEmployee); From ee348750a6501395418802e80c72b4420537c9bb Mon Sep 17 00:00:00 2001 From: maruf128 Date: Wed, 14 Jun 2023 16:06:49 +0200 Subject: [PATCH 59/63] tijdslot admin/mederwerker --- Presentation/Reservation/ReservationView.cs | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 498429f..54c02b6 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -107,11 +107,23 @@ static public void MakeReservation() } while (!isValidDate); - string TimeSlot; + string TimeSlot = ""; do { - Console.Write("Time (00:00): "); - TimeSlot = Console.ReadLine()!; + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { $"{Date}", "Selecteer een tijdslot:" }, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); + + switch (selectedClass) + { + case 0: + TimeSlot = "16:00"; + break; + case 1: + TimeSlot = "18:00"; + break; + case 2: + TimeSlot = "20:00"; + break; + } } while (ValidationLogic.IsValidTime(TimeSlot) != true); @@ -128,6 +140,13 @@ static public void MakeReservation() Console.ReadKey(); return; } + // je weet nu hoeveel mensen er zullen komen voeg (maruf) functie's toe om te weten hoeveel het zal kosten + Prijs geld = new Prijs(); + decimal money = geld.prijs(Amt_People); + + Console.WriteLine($"\nIn totaal betaal je voor {Amt_People} mensen {money} euro."); + Console.WriteLine("Druk op iets om verder te gaan..."); + Console.ReadKey(); List AvailableTables = TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Amt_People); From 6a381084cc176c91fa8c64a452b04f4b5469fdfc Mon Sep 17 00:00:00 2001 From: Henno85657 <85657@glr.nl> Date: Wed, 14 Jun 2023 17:04:55 +0200 Subject: [PATCH 60/63] small changes --- DataSources/accounts.json | 2 +- DataSources/reservations.json | 35 +++++-- Presentation/AccountData.cs | 8 +- Presentation/Reservation/ReservationView.cs | 105 ++++++++++++++------ 4 files changed, 104 insertions(+), 46 deletions(-) diff --git a/DataSources/accounts.json b/DataSources/accounts.json index fc6719c..6731b17 100644 --- a/DataSources/accounts.json +++ b/DataSources/accounts.json @@ -59,7 +59,7 @@ "id": 9, "emailAddress": "henno.passchier@gmail.com", "password": "Abc123!", - "fullName": "Henno Passchier", + "fullName": "henno passchier", "level": 0 }, { diff --git a/DataSources/reservations.json b/DataSources/reservations.json index 56847db..4df07a6 100644 --- a/DataSources/reservations.json +++ b/DataSources/reservations.json @@ -22,20 +22,39 @@ "Date": "2023-12-09T00:00:00", "ReservationCode": "PM8H3K", "TimeSlot": "16:00:00", - "Tables": [], + "Tables": [ + "2" + ], "Amt_People": 2, "CourseMenu": null, "Verified": false }, { - "ID": 3, + "ID": 5, "ClientNumber": 0, - "Name": "dkkda", - "Email": "daa@dada.co", - "Date": "2023-12-09T00:00:00", - "ReservationCode": "WA2F7M", - "TimeSlot": "16:00:00", - "Tables": [], + "Name": "Henno Passchier", + "Email": "henno.passchier@gmail.com", + "Date": "2023-06-15T00:00:00", + "ReservationCode": "LJ8V4G", + "TimeSlot": "20:00:00", + "Tables": [ + "1" + ], + "Amt_People": 2, + "CourseMenu": null, + "Verified": false + }, + { + "ID": 6, + "ClientNumber": 9, + "Name": "Henno Passchier", + "Email": "henno.passchier@gmail.com", + "Date": "2023-06-16T00:00:00", + "ReservationCode": "MN4Z4J", + "TimeSlot": "20:00:00", + "Tables": [ + "4" + ], "Amt_People": 2, "CourseMenu": null, "Verified": false diff --git a/Presentation/AccountData.cs b/Presentation/AccountData.cs index 6b6feaa..f551f7f 100644 --- a/Presentation/AccountData.cs +++ b/Presentation/AccountData.cs @@ -48,11 +48,7 @@ static public void Start(int id) // ingelogd geef parameter's mee om aan te geve { Console.WriteLine("Graag hier je volledige naam invullen:"); acc.FullName = Console.ReadLine()!.ToLower(); - if (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")) - { - Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); - } - } while (!Regex.IsMatch(acc.FullName, @"^[A-Za-z\\s]+$")); + } while (ValidationLogic.IsValidFullname(acc.FullName) != true); // updates full name to json and returns to Start accountsLogic.UpdateList(acc); @@ -60,7 +56,7 @@ static public void Start(int id) // ingelogd geef parameter's mee om aan te geve } else if (selectedClass == 3) { - var ReservationList = ReservationLogic.GetReservations(acc.EmailAddress); // filters all reservations with this email, maybe change this to clientnumber + var ReservationList = ReservationLogic.GetReservations(id); // filters all reservations with this email, maybe change this to clientnumber Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine($"Reservaties Tabel van {acc.FullName}:"); Console.ForegroundColor = ConsoleColor.White; diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 54c02b6..6d4130d 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -92,25 +92,26 @@ static public void MakeReservation() Console.Write("Date (DD-MM-JJJJ): "); Date = Console.ReadLine()!; - if (!DateTime.TryParseExact(Date, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)) + if (!ValidationLogic.IsValidDate(Date)) { Console.WriteLine("Veerkde datum. Vul een juiste formaat in: DD-MM-JJJJ."); } - else if (parsedDate < temp) + else if (DateTime.Parse(Date) < temp) { Console.WriteLine("De datum moet wel in de toekomst zitten"); } else { isValidDate = true; + } } while (!isValidDate); - + string TimeSlot = ""; do { - int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { $"{Date}", "Selecteer een tijdslot:" }, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { $"{DateTime.Parse(Date).ToString("dddd, dd MMMM yyyy")}", "Selecteer een tijdslot:" }, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); switch (selectedClass) { @@ -127,12 +128,14 @@ static public void MakeReservation() } while (ValidationLogic.IsValidTime(TimeSlot) != true); - int Amt_People; + string Amt_People_Check; do { Console.Write("Aantal Personen: "); - Amt_People = Convert.ToInt32(Console.ReadLine()); - } while (Amt_People <= 0); + Amt_People_Check = Console.ReadLine()!; + } while (ValidationLogic.IsNumeric(Amt_People_Check) != true); + + int Amt_People = Convert.ToInt32(Amt_People_Check); if (TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Amt_People).Count < 1) { @@ -185,6 +188,7 @@ static public void MakeReservation() if (CorrectedTables.Contains(TableNumber)) { TableChecker = false; + Tables.Add(TableNumber); } else { @@ -239,7 +243,7 @@ static public void ChangeReservation() { Console.Write("Naam: "); Name = Console.ReadLine()!; - } while (Name.Length <= 3); + } while (ValidationLogic.IsValidFullname(Name) != true); string Email; do @@ -257,59 +261,98 @@ static public void ChangeReservation() Console.Write("Date (DD-MM-JJJJ): "); Date = Console.ReadLine()!; - if (!DateTime.TryParseExact(Date, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)) + if (!ValidationLogic.IsValidDate(Date)) { Console.WriteLine("Veerkde datum. Vul een juiste formaat in: DD-MM-JJJJ."); } - else if (parsedDate < temp) + else if (DateTime.Parse(Date) < temp) { Console.WriteLine("De datum moet wel in de toekomst zitten"); } else { isValidDate = true; + } } while (!isValidDate); - string TimeSlot; + string TimeSlot = ""; do { - Console.Write("Time (00:00): "); - TimeSlot = Console.ReadLine()!; + int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { $"{DateTime.Parse(Date).ToString("dddd, dd MMMM yyyy")}", "Selecteer een tijdslot:" }, "16:00 - 18:00", "18:00 - 20:00", "20:00 - 22:00"); + + switch (selectedClass) + { + case 0: + TimeSlot = "16:00"; + break; + case 1: + TimeSlot = "18:00"; + break; + case 2: + TimeSlot = "20:00"; + break; + } } while (ValidationLogic.IsValidTime(TimeSlot) != true); - string Amt_People; + + string Amt_People_Check; do { Console.Write("Aantal Personen: "); - Amt_People = Console.ReadLine()!; - } while (ValidationLogic.IsNumeric(Amt_People) != true); + Amt_People_Check = Console.ReadLine()!; + } while (ValidationLogic.IsNumeric(Amt_People_Check) != true); - Console.WriteLine("Beschikbare tafels: " + string.Join(", ", TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Convert.ToInt32(Amt_People)))); - Console.WriteLine("Tafel nummers"); - List Tables = new List(); - while (true) + int Amt_People = Convert.ToInt32(Amt_People_Check); + + List AvailableTables = TableLogic.CheckTables(DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Amt_People); + + TimeSpan tempTime; + + TimeSpan.TryParse(TimeSlot, out tempTime); + + DateTime tempDate; + DateTime.TryParse(Date, out tempDate); + + ReservationLogic.ShowTablesAvailability(tempDate, tempTime, Amt_People); + + List CorrectedTables = new List(); + foreach (string table in AvailableTables) { - string Table_number = Console.ReadLine()!; - if (Table_number != "") + if (table.Length > 1) { - try - { - Tables.Add(Table_number); - } - catch - { - Console.WriteLine("Toevoegen mislukt, voer tafel nummers in!"); - } + string tableCorrect; + tableCorrect = table.Remove(0, 1); + CorrectedTables.Add(tableCorrect); } else { - break; + CorrectedTables.Add(table); } + } + Console.WriteLine($"Tafelnummers beschikbaar: " + string.Join(", ", CorrectedTables)); + + Console.WriteLine("Schrijf de tafel nummer?"); + List Tables = new List(); + bool TableChecker = true; + string TableNumber = Console.ReadLine()!; + while (TableChecker is true) + { + if (CorrectedTables.Contains(TableNumber)) + { + TableChecker = false; + Tables.Add(TableNumber); + } + else + { + Console.WriteLine("Graag een geldige tafel nummer typen."); + TableNumber = Console.ReadLine()!; + } } + // All values has been checked and ready to be changed bool ChangedValue = ReservationLogic.ChangeReservation(Searchterm, Name, Email, DateTime.Parse(Date), TimeSpan.Parse(TimeSlot), Tables, Convert.ToInt32(Amt_People)); From 4863a17429cc453cc32751f5dbf6149e2ce450a6 Mon Sep 17 00:00:00 2001 From: maruf128 Date: Thu, 15 Jun 2023 14:34:50 +0200 Subject: [PATCH 61/63] kleine fixes nog aan mederwerker en locatie --- Logic/InformatieLogic.cs | 2 +- Presentation/Mederwerker.cs | 39 +++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Logic/InformatieLogic.cs b/Logic/InformatieLogic.cs index 62bea05..e91e7ff 100644 --- a/Logic/InformatieLogic.cs +++ b/Logic/InformatieLogic.cs @@ -143,7 +143,7 @@ public static void UpdateLocation(string username, int id) // maak nu functie om te kijken of de eind tijd wel later is dan de begin tijd if (IsEndTimeLater(Neweindtijd, Newbegintijd)) { - Console.WriteLine("Error: End time must be later than start time. Please try again. (press enter)"); + Console.WriteLine("Error: Sluitings tijd moet later zijn dan openingstijd, probeer opnieuw. (press enter)"); Console.ReadKey(); break; } diff --git a/Presentation/Mederwerker.cs b/Presentation/Mederwerker.cs index 98637d6..a130cdb 100644 --- a/Presentation/Mederwerker.cs +++ b/Presentation/Mederwerker.cs @@ -58,20 +58,35 @@ public static void Mederwerker_gegevens(string username, int id) fullName = Console.ReadLine()!; } while (ValidationLogic.IsValidFullname(fullName) != true); - // create new employee object - AccountModel newEmployee = new AccountModel( - accountsLogic.GetLastID() + 1, - emailAddress ?? string.Empty, - password ?? string.Empty, - fullName ?? string.Empty, - 2 - ); - // add new employee to accounts - accountsLogic.UpdateList(newEmployee); - Console.WriteLine("Nieuwe medewerker is toegevoegd."); - ManagerMenu.Admin_menu(username, id); // zodat je terug gaat + AccountModel? acc = accountsLogic.CheckRegistration(emailAddress); + if (acc == null) + { + // create new employee object + AccountModel newEmployee = new AccountModel( + accountsLogic.GetLastID() + 1, + emailAddress ?? string.Empty, + password ?? string.Empty, + fullName ?? string.Empty, + 2 + ); + accountsLogic.UpdateList(newEmployee); + // add new employee to accounts + accountsLogic.UpdateList(newEmployee); + + Console.WriteLine("Nieuwe medewerker is toegevoegd."); + Console.ReadKey(); + ManagerMenu.Admin_menu(username, id); // zodat je terug gaat + } + else + { + Console.WriteLine("De email die u heeft ingevuld is al gekoppeld aan een account."); + Console.WriteLine("Probeer het opnieuw."); + Console.ReadKey(); + ManagerMenu.Admin_menu(username, id); + } + } From de79259e4759b59a63eb6bf93c7e2ad05d0749ec Mon Sep 17 00:00:00 2001 From: Henno0701 <1048091@hr.nl> Date: Thu, 15 Jun 2023 15:58:44 +0200 Subject: [PATCH 62/63] Error fix --- Presentation/Reservation/ReservationView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 6d4130d..d077b21 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -61,7 +61,7 @@ static public void MakeReservation() } catch (Exception e) { - Console.WriteLine(e); + Console.WriteLine("Account niet gevonden!"); HasAccount = "N"; } From 1710d19f753dd897ef1bcaa7a94db21eb0c2dd17 Mon Sep 17 00:00:00 2001 From: Henno85657 <85657@glr.nl> Date: Thu, 15 Jun 2023 17:19:40 +0200 Subject: [PATCH 63/63] AutoVerifing --- Logic/ReservationLogic.cs | 40 +++++++++++++++++++++++++++++++-------- Presentation/Menu.cs | 1 + 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index 95b1c99..73be9b0 100644 --- a/Logic/ReservationLogic.cs +++ b/Logic/ReservationLogic.cs @@ -58,7 +58,7 @@ public static bool AddReservation(int _id, int _clientnumber, string _name, stri } catch (Exception ex) { // Catch the error and return false - Console.WriteLine(ex); + Console.WriteLine("Niet gelukt!"); return false; } } @@ -75,7 +75,7 @@ public static List GetReservations() } catch (Exception ex) { - Console.WriteLine(ex); + Console.WriteLine("Niet gelukt!"); // Console.WriteLine($"Error: {ex.Message}"); } return new List(); @@ -102,7 +102,7 @@ public static List GetReservations(string _Searchterm) } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + Console.WriteLine("Niet gelukt!"); } return new List(); } @@ -127,7 +127,7 @@ public static List GetReservations(int clientnumber) } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + Console.WriteLine("Niet gelukt!"); } return new List(); } @@ -154,7 +154,7 @@ public static List GetReservations(int clientnumber) } catch (Exception ex) { - Console.WriteLine(ex); + Console.WriteLine("Niet gelukt!"); return null; } } @@ -188,7 +188,7 @@ public static bool ChangeReservation(string _Searchterm, string _name, string _e } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + Console.WriteLine("Niet gelukt!"); return false; } } @@ -211,7 +211,7 @@ public static bool DeleteReservation(int _ID) } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + Console.WriteLine("Niet gelukt!"); return false; } } @@ -234,11 +234,35 @@ public static bool VerifyingReservation(int _ID) } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + Console.WriteLine("Niet gelukt!"); return false; } } + public static void AutoVerifing() + { + try + { + //Get reservations from other function + List reservations = GetReservations(); + + DateTime temp = DateTime.Now; + //Set every date below today to Verified: true + reservations.Where(x => (x.Date.AddDays(-1)) <= temp).ToList().ForEach(x => x.Verified = true); + + //Send data back to JSON file + string updatedJson = JsonConvert.SerializeObject(reservations, Formatting.Indented); + File.WriteAllText("DataSources/reservations.json", updatedJson); + + return; + } + catch (Exception ex) + { + Console.WriteLine("Niet gelukt!"); + return ; + } + } + public static void UpdateTableAvailability(List TablesList) { _6A = TablesList.Contains("_6A") ? available : unavailable; diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index 58d4af6..35108bf 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -5,6 +5,7 @@ static class Menu // start menu, niet ingelogd. static public void Start() { + ReservationLogic.AutoVerifing(); Console.Clear(); int selectedClass = MenuLogic.MultipleChoice(true, "○", 1, new string[] { }, "Login", "Menu Kaart", "Reserveren", "Reservering ophalen", "Restaurant Informatie",