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/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 new file mode 100644 index 0000000..e056723 --- /dev/null +++ b/DataModels/Customer.cs @@ -0,0 +1,8 @@ +class Customer : AccountModel, IAccount +{ + 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..df2f204 --- /dev/null +++ b/DataModels/Employee.cs @@ -0,0 +1,8 @@ +class Employee : AccountModel, IAccount +{ + 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/FoodModel.cs b/DataModels/FoodModel.cs new file mode 100644 index 0000000..b3eb3d6 --- /dev/null +++ b/DataModels/FoodModel.cs @@ -0,0 +1,30 @@ +// 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 Soups { get; set; } + public List Mains { get; set; } + 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(); + Soups = new List(); + Mains = new List(); + Desserts = new List(); + Drinks = new List(); + Wijn = new List(); + Gangen = new List(); + } + +} \ No newline at end of file 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/Location.cs b/DataModels/Location.cs new file mode 100644 index 0000000..b92136b --- /dev/null +++ b/DataModels/Location.cs @@ -0,0 +1,40 @@ +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); + } +} diff --git a/DataModels/Manager.cs b/DataModels/Manager.cs new file mode 100644 index 0000000..ab9014e --- /dev/null +++ b/DataModels/Manager.cs @@ -0,0 +1,8 @@ +class Manager : AccountModel, IAccount +{ + 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/DataModels/ReservationModel.cs b/DataModels/ReservationModel.cs index 4519c20..17e2320 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;} @@ -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/DataSources/Informatie.json b/DataSources/Informatie.json new file mode 100644 index 0000000..42e8040 --- /dev/null +++ b/DataSources/Informatie.json @@ -0,0 +1,16 @@ +{ + "Name": "Jake", + "Address": "Wijnhaven 107", + "Phone": "0695684596", + "Email": "JakeRestaurant@gmail.com", + "Website": null, + "OpeningHours": { + "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", + "vrijdag": "18:00-22:00", + "zaterdag": "18:00-22:00" + } +} \ No newline at end of file diff --git a/DataSources/accounts.json b/DataSources/accounts.json index b8b109c..6731b17 100644 --- a/DataSources/accounts.json +++ b/DataSources/accounts.json @@ -58,8 +58,15 @@ { "id": 9, "emailAddress": "henno.passchier@gmail.com", - "password": "abc", - "fullName": "Henno Passchier", + "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/DataSources/menu.json b/DataSources/menu.json index 480c0fe..2475272 100644 --- a/DataSources/menu.json +++ b/DataSources/menu.json @@ -1 +1,112 @@ -{"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.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.5 + }, + { + "ID": 3, + "Category": null, + "Name": "4 Gangen menu", + "Price": 25.5 + }, + { + "ID": 4, + "Category": null, + "Name": "Wijn arrangement", + "Price": 12.50 + } + ] +} \ No newline at end of file diff --git a/DataSources/reservations.json b/DataSources/reservations.json index a2b8fc7..4df07a6 100644 --- a/DataSources/reservations.json +++ b/DataSources/reservations.json @@ -2,16 +2,61 @@ { "ID": 1, "ClientNumber": 0, + "Name": "12-09", + "Email": "adadam@gmail.com", + "Date": "2023-12-09T00:00:00", + "ReservationCode": "RL6S8P", + "TimeSlot": "16:00:00", + "Tables": [ + "1" + ], + "Amt_People": 2, + "CourseMenu": null, + "Verified": false + }, + { + "ID": 2, + "ClientNumber": 0, + "Name": "jeffrey", + "Email": "jeffrey@het.com", + "Date": "2023-12-09T00:00:00", + "ReservationCode": "PM8H3K", + "TimeSlot": "16:00:00", + "Tables": [ + "2" + ], + "Amt_People": 2, + "CourseMenu": null, + "Verified": false + }, + { + "ID": 5, + "ClientNumber": 0, "Name": "Henno Passchier", "Email": "henno.passchier@gmail.com", - "Date": "2023-05-26T00:00:00", - "ReservationCode": "XF3S7M", + "Date": "2023-06-15T00:00:00", + "ReservationCode": "LJ8V4G", "TimeSlot": "20:00:00", "Tables": [ "1" ], "Amt_People": 2, - "CourseMenu": 0, + "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 } ] \ No newline at end of file diff --git a/Logic/AccountsLogic.cs b/Logic/AccountsLogic.cs index 90d4ecd..88d9732 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() ?? new List(); + } - 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; + } } diff --git a/Logic/Email.cs b/Logic/Email.cs index 882bfbc..b2d9d06 100644 --- a/Logic/Email.cs +++ b/Logic/Email.cs @@ -3,13 +3,13 @@ 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, 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/Logic/FoodMenu.cs b/Logic/FoodMenu.cs index e964891..3e819bb 100644 --- a/Logic/FoodMenu.cs +++ b/Logic/FoodMenu.cs @@ -1,37 +1,12 @@ 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 Foodmenu() - { - // stel ze vast door een nieuwe lijst te maken - Starters = new List(); - Mains = new List(); - Desserts = new List(); - Drinks = new List(); - } - -} // maak de menu importer 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) @@ -50,32 +25,46 @@ 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) - { - 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) + if (data != null) { - menu.Desserts.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 }); + } } - - foreach (var item in data.Drinks) - { - menu.Drinks.Add(new MenuItem { ID = item.ID, Name = item.Name, Price = item.Price }); - } - return menu; } public static void AddMenuItem(Foodmenu menu, MenuItem item, string filename) @@ -88,6 +77,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 @@ -103,6 +97,16 @@ 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; + 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"); } @@ -129,12 +133,21 @@ public static void RemoveItem(Foodmenu menu, string category, int id, string fil case "Drinks": itemList = menu.Drinks; break; + case "Wijn": + itemList = menu.Wijn; + break; + case "Soups": + itemList = menu.Wijn; + break; + case "Gangen": + itemList = menu.Gangen; + break; default: throw new Exception("Invalid category specified"); } // 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) @@ -153,7 +166,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..c16e13e 100644 --- a/Logic/Food_Aanpassen.cs +++ b/Logic/Food_Aanpassen.cs @@ -5,11 +5,11 @@ 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(); - switch (input.ToUpper()) + string? input = Console.ReadLine(); + switch (input?.ToUpper()) { case "1": AddItem(username, id); @@ -18,8 +18,14 @@ public static void EditMenu(string username, int id) RemoveItem(username, id); break; case "3": - ChangeItem(username, id); + ChangePrice(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; @@ -31,17 +37,19 @@ 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/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) { case "Starters": + case "Soups": case "Mains": case "Desserts": case "Drinks": + case "Wijn": break; default: Console.WriteLine("Ongeldige categorie. Kies opnieuw."); @@ -49,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); @@ -87,18 +95,19 @@ 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/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 + // Check if the category is valid switch (category) { case "Starters": + case "Soups": case "Mains": case "Desserts": case "Drinks": + case "Wijn": break; default: Console.WriteLine("Ongeldige categorie. Kies opnieuw."); @@ -106,20 +115,30 @@ 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()); + 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": 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; @@ -129,6 +148,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 @@ -144,6 +166,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; @@ -153,96 +178,172 @@ 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(); - // 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()); - - // get the menu from the JSON file + // 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); - // find the item in the menu based on the category and ID - MenuItem itemToChange = null; - switch (category) + // 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; + switch (selectedClass) { - case "Starters": - itemToChange = menu.Starters.FirstOrDefault(i => i.ID == id); + case 0: + // it's the 2 gangen menu + GangenMenu = GetGangenMenu(1, menu.Gangen); break; - case "Mains": - itemToChange = menu.Mains.FirstOrDefault(i => i.ID == id); + case 1: + // it's the 3 gangen menu + GangenMenu = GetGangenMenu(2, menu.Gangen); break; - case "Desserts": - itemToChange = menu.Desserts.FirstOrDefault(i => i.ID == id); + case 2: + // it's the 4 gangen menu + GangenMenu = GetGangenMenu(3, menu.Gangen); break; - case "Drinks": - itemToChange = menu.Drinks.FirstOrDefault(i => i.ID == id); + case 3: + // het is de wijn arrangement + GangenMenu = GetGangenMenu(4, menu.Gangen); break; } - // if the item was not found, notify the user and return - if (itemToChange == null) + // check if the menu item is found + if (GangenMenu != null) { - Console.WriteLine($"Item met ID {id} kon niet worden gevonden in de categorie {category}."); - return; - } + 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); - // ask for the new name - Console.WriteLine($"Huidige naam: {itemToChange.Name}"); - Console.WriteLine("Voer de nieuwe naam in:"); - string name = Console.ReadLine(); + // update the price of the menu item + GangenMenu.Price = newPrice; - // check if the new name is not empty - if (string.IsNullOrWhiteSpace(name)) + // 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("Naam mag niet leeg zijn. Kies opnieuw."); - ChangeItem(username, user_id); - return; + Console.WriteLine("Er gaat iets fout!."); } - // 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)) + ManagerMenu.Admin_menu(username, user_id); // return to the admin menu + } + + private static MenuItem? GetGangenMenu(int id, List items) + { + foreach (MenuItem item in items) { - Console.WriteLine("Ongeldige prijs. Kies opnieuw."); - ChangeItem(username, user_id); - return; + 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) + // { + // // 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(); - // update the item in the menu and save the changes to the JSON file - itemToChange.Name = name; - itemToChange.Price = price; - MenuImporter.SaveMenuToJson(menu, filenaam); + // // 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; + // } - Console.WriteLine($"Item met ID {itemToChange.ID} is succesvol aangepast in de categorie {category}."); - ManagerMenu.Admin_menu(username, user_id);// zodat je terug gaat - } + // // 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); + + // // 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; + // } + + // // 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; + // } + + // // 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); + + // 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/Logic/InformatieLogic.cs b/Logic/InformatieLogic.cs new file mode 100644 index 0000000..e91e7ff --- /dev/null +++ b/Logic/InformatieLogic.cs @@ -0,0 +1,187 @@ +namespace Project_B.Logic; +using System.Text; +using System.Text.RegularExpressions; +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; + if (location != null) + { + 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("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 2: + // 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 + 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: + 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 + 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: + // 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? 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: Sluitings tijd moet later zijn dan openingstijd, probeer opnieuw. (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; + } + else + { + Console.WriteLine($"Invalid day: {dayToEdit}"); + } + 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(); + } + private static bool IsEndTimeLater(string startTime, string endTime) + { + DateTime startDateTime = DateTime.Parse(startTime); + DateTime endDateTime = DateTime.Parse(endTime); + + return endDateTime > startDateTime; + } +} 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/MenuLogic.cs b/Logic/MenuLogic.cs index d77711e..cb44581 100644 --- a/Logic/MenuLogic.cs +++ b/Logic/MenuLogic.cs @@ -18,6 +18,7 @@ public static int MultipleChoice(bool canCancel, string symbol, int opl, string[ do { + // if (canClear == true) Console.Clear(); Console.Clear(); Console.ForegroundColor = ConsoleColor.White; diff --git a/Logic/Prijs.cs b/Logic/Prijs.cs index 4004d1c..203ed11 100644 --- a/Logic/Prijs.cs +++ b/Logic/Prijs.cs @@ -1,15 +1,40 @@ 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 decimal wijn_arrangement; + 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; + } + else if (x.Name == "Wijn arrangement") + { + wijn_arrangement = x.Price; + } + } + } // Field for the discount percentage - public double discount = 0.1; + public decimal discount = 0.1M; // 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?"); @@ -31,11 +56,40 @@ 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?"); + 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(); + wineCount = string.IsNullOrEmpty(inputWineCount) ? 0 : Convert.ToInt32(inputWineCount); - double menuPrijs = 0.0; + + 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 + // ... + } + } + decimal menuPrijs = 0; // Calculate the price based on the chosen menu switch (menu) @@ -51,16 +105,22 @@ 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 + decimal wijnprijs = wijn_arrangement * wineCount; + totPrijs += wijnprijs; + } return totPrijs; } } diff --git a/Logic/ReservationLogic.cs b/Logic/ReservationLogic.cs index 4a5d4bb..73be9b0 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(); @@ -51,83 +53,124 @@ 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 + catch (Exception ex) + { // Catch the error and return false + Console.WriteLine("Niet gelukt!"); 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); - return reservations != null ? reservations : new List(); + string jsonContent = File.ReadAllText(@"DataSources/reservations.json"); + List? reservations = JsonConvert.DeserializeObject>(jsonContent); + return reservations?.Count > 0 ? reservations : new List(); } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + Console.WriteLine("Niet gelukt!"); + // Console.WriteLine($"Error: {ex.Message}"); } 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(); - // 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 || reservation.ReservationCode == _Searchterm) + { + ResList.Add(reservation); //Return the reservation + } + } + return ResList; //Return nothing if nothing came out + } + catch (Exception ex) + { + Console.WriteLine("Niet gelukt!"); + } + 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 (Convert.ToString(reservation.ID) == _Searchterm || reservation.Name == _Searchterm || reservation.Email == _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}"); + Console.WriteLine("Niet gelukt!"); } 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(); - // 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) { + 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 + //Return nothing if nothing came out + return null; } catch (Exception ex) { + Console.WriteLine("Niet gelukt!"); return null; } } - 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; @@ -140,12 +183,12 @@ 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) { - Console.WriteLine($"Error: {ex.Message}"); + Console.WriteLine("Niet gelukt!"); return false; } } @@ -153,7 +196,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(); @@ -161,19 +205,21 @@ 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; } catch (Exception ex) { - Console.WriteLine($"Error: {ex.Message}"); + Console.WriteLine("Niet gelukt!"); return false; } } - public static bool VerifyingReservation(int _ID) { - try { + public static bool VerifyingReservation(int _ID) + { + try + { //Get reservations from other function List reservations = GetReservations(); @@ -183,35 +229,40 @@ 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("Niet gelukt!"); return false; } } - public static bool AccessReservationSimulation(string _ReservationCode) { - try { + public static void AutoVerifing() + { + try + { //Get reservations from other function List reservations = GetReservations(); - DateTime DateNow = DateTime.Now; + 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); - //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; + //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; @@ -249,8 +300,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(); + } + + } } @@ -300,11 +356,19 @@ 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() { //Creating object of random class diff --git a/Logic/TableLogic.cs b/Logic/TableLogic.cs index ac0f231..93305d0 100644 --- a/Logic/TableLogic.cs +++ b/Logic/TableLogic.cs @@ -11,34 +11,50 @@ 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) { + 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) { + + + if (persons == 6 || persons == 5) + { AvailableTables = AvailableTables.Where(table => table.StartsWith("_6") && table.Length == 3).ToList(); - } else if (persons == 4 || persons == 3) { + } + else if (persons == 4 || persons == 3) + { AvailableTables = AvailableTables.Where(table => table.StartsWith("_4") && table.Length == 3).ToList(); - } else if (persons == 2) { + } + 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 +62,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/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/AccountData.cs b/Presentation/AccountData.cs index c5c72bf..f551f7f 100644 --- a/Presentation/AccountData.cs +++ b/Presentation/AccountData.cs @@ -11,81 +11,81 @@ 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(); + } while (ValidationLogic.IsValidFullname(acc.FullName) != true); - // 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(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; + 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 diff --git a/Presentation/CustomerMenu.cs b/Presentation/CustomerMenu.cs index ca92c33..5c735e1 100644 --- a/Presentation/CustomerMenu.cs +++ b/Presentation/CustomerMenu.cs @@ -1,49 +1,53 @@ 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); + } + Console.ReadKey(); + 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 diff --git a/Presentation/ManagerMenu.cs b/Presentation/ManagerMenu.cs index 42a3054..612cc92 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,22 +25,21 @@ 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); break; case 1: Reservation.MakeReservation(); - Console.WriteLine("Druk op iets om verder te gaan..."); Console.ReadKey(); Admin_menu(username, id); @@ -58,11 +59,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 +73,37 @@ static public void Admin_menu(string username, int id) break; } break; + case 3: + 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(); + if (location != null) + { + 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 + Menu.Start(); + break; + default: + // iets ging fout + Admin_menu(username, id); + break; } } } \ No newline at end of file diff --git a/Presentation/Mederwerker.cs b/Presentation/Mederwerker.cs index bf7b540..a130cdb 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"; @@ -9,45 +10,83 @@ 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) { 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(); + } while (ValidationLogic.IsValidEmail(emailAddress) != true && emailAddress != "1"); - Console.Write("Wachtwoord: "); - string password = Console.ReadLine(); + do + { + 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); - Console.Write("Volledige naam: "); - string fullName = Console.ReadLine(); + do + { + 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); - // create new employee object - AccountModel newEmployee = new AccountModel(accountsLogic.GetLastID() + 1, emailAddress, password, fullName, 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); + } + } diff --git a/Presentation/Menu.cs b/Presentation/Menu.cs index c0fd890..35108bf 100644 --- a/Presentation/Menu.cs +++ b/Presentation/Menu.cs @@ -5,7 +5,9 @@ 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", "Registreren", "Stoppen"); if (selectedClass == 0) @@ -22,6 +24,7 @@ static public void Start() { ReservationConsole res = new ReservationConsole(); res.Reserveren(); + Start(); } else if (selectedClass == 3) { @@ -30,8 +33,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(); } @@ -52,16 +58,23 @@ 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 + WorkerMenu.Start(persoon.FullName, persoon.Id); + } + 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/Reservation/MyReservation.cs b/Presentation/Reservation/MyReservation.cs index bc110e3..2c2b51a 100644 --- a/Presentation/Reservation/MyReservation.cs +++ b/Presentation/Reservation/MyReservation.cs @@ -2,53 +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(); - 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); + 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 { + } + 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 - 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"); + 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(); @@ -56,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; @@ -82,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: @@ -113,41 +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 - 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"); + 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(); @@ -155,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; @@ -181,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: @@ -207,23 +248,22 @@ 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; - } } } - } - if (Found != true) { - Console.WriteLine("\nGeen reservering gevonden, heeft u de juiste code ingevoerd?\nDruk op iets om door te gaan..."); + 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 1e3aba4..e834387 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() { @@ -31,28 +32,59 @@ 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 name = nameCheck; + Console.Clear(); + + string phoneCheck; + string phonePattern = @"^(?:\+31|0)6\d{8}$"; + + do + { + Console.WriteLine("(Optioneel) Wat is uw telefoon nummer? (+31612345678 or 0612345678)"); + phoneCheck = Console.ReadLine()!; + + if (!Regex.IsMatch(phoneCheck, phonePattern)) + { + Console.WriteLine("Dit is geen valide telefoon nummer!"); + } + + } while (!Regex.IsMatch(phoneCheck, phonePattern) && phoneCheck == null); + + Console.Clear(); + string emailCheck; 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; - + 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; @@ -70,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: @@ -80,17 +111,21 @@ 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."); + 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(); bool field4Valid = false; while (field4Valid is false) { + Console.Clear(); string DateCheck; 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) @@ -105,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"); @@ -121,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); @@ -133,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); @@ -144,11 +182,12 @@ public void Reserveren() reservationcode = text; + string tableCheck; 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; @@ -160,8 +199,10 @@ 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.warning(); + EmailFunction.sendmail(email, name, reservationcode, date, timeslot); + EmailFunction.warning(); + // terug naar de menu uitgelogd + Menu.Start(); } catch { @@ -181,19 +222,32 @@ 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; + 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; + 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"); @@ -218,21 +272,21 @@ 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(); + 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(); bool field4Valid = false; while (field4Valid is false) { + Console.Clear(); string DateCheck; 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) @@ -247,7 +301,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"); @@ -263,9 +317,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); @@ -275,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); @@ -290,7 +347,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; @@ -300,14 +357,18 @@ public void Reserveren(int client_id, string username) tables.Add(tableCheck); try { - ReservationLogic.AddReservation(id, clientnumber, name, email, date, reservationcode, timeslot, tables, amt_people); - Console.WriteLine("Geluk!"); - Email.sendmail(email, name, date, timeslot); - Email.warning(); + ReservationLogic.AddReservation(id, clientnumber, name, email!, date, reservationcode, timeslot, tables, amt_people); + Console.WriteLine("Gelukt!"); + 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"); + Console.ReadKey(); + CustomerMenu.Start(username, client_id); } catch (Exception e) { - Console.WriteLine("Niet Geluk!"); + Console.WriteLine(e); return; } diff --git a/Presentation/Reservation/ReservationView.cs b/Presentation/Reservation/ReservationView.cs index 2fd323d..d077b21 100644 --- a/Presentation/Reservation/ReservationView.cs +++ b/Presentation/Reservation/ReservationView.cs @@ -1,11 +1,15 @@ using Newtonsoft.Json; using Project_B.Logic; using Project_B.DataModels; +using System.Globalization; + +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,20 +17,23 @@ 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(); + HasAccount = Console.ReadLine()!.ToUpper(); } while (HasAccount != "J" && HasAccount != "N"); string ClientNumber = "0"; @@ -34,80 +41,160 @@ 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(); + SearchTerm = Console.ReadLine()!.ToLower(); } while (SearchTerm.Length == 0); - try { - AccountModel AccountData = accountsLogic.GetByEmail(SearchTerm); - - ClientNumber = Convert.ToString(AccountData.Id); + 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(); + Name = Console.ReadLine()!; } while (Name.Length <= 3); - - do { + + do + { Console.Write("Email: "); - Email = Console.ReadLine(); + Email = Console.ReadLine()!; } while (ValidationLogic.IsValidEmail(Email) != true); } string Date; - do { + 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 (!ValidationLogic.IsValidDate(Date)) + { + Console.WriteLine("Veerkde datum. Vul een juiste formaat in: DD-MM-JJJJ."); + } + else if (DateTime.Parse(Date) < temp) + { + Console.WriteLine("De datum moet wel in de toekomst zitten"); + } + else + { + isValidDate = true; - string TimeSlot; - do { - Console.Write("Time (00:00): "); - TimeSlot = Console.ReadLine(); + } + } while (!isValidDate); + + + string TimeSlot = ""; + do + { + 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); - int Amt_People; - do { + 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) + { + Console.WriteLine($"Er is geen plek meer voor vandaag probeer een andere dag"); + 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); - Console.WriteLine($"Tafelnummers beschikbaar: " + string.Join(", ", AvailableTables)); - - Console.WriteLine("Tafel nummers (klaar ENTER)"); - List Tables = new List (); - while (true) { - string Table_number = Console.ReadLine(); - - // 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!"); - } - } else { - break; + + + 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) + { + if (table.Length > 1) + { + string tableCorrect; + tableCorrect = table.Remove(0, 1); + CorrectedTables.Add(tableCorrect); } + 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; + Tables.Add(TableNumber); + } + else + { + Console.WriteLine("Graag een geldige tafel nummer typen."); + TableNumber = Console.ReadLine()!; + } } @@ -115,86 +202,184 @@ 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() { - Console.Write("Zoeken (ID / Naam / Email): "); - string Searchterm = Console.ReadLine(); + static public void ChangeReservation() + { + Console.Write("Zoeken (ID / Naam / Email / Reservering Code): "); + string Searchterm = Console.ReadLine()!; + + List r = ReservationLogic.GetReservations(Searchterm); + + if (r != null) + { + 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); + + Searchterm = Array_r_choices[selectedClass].Split("]")[0].Remove(0, 1); + + } - if (ReservationLogic.GetReservation(Searchterm) != null) { string Name; - do { + do + { Console.Write("Naam: "); - Name = Console.ReadLine(); - } while (Name.Length <= 3); - + Name = Console.ReadLine()!; + } while (ValidationLogic.IsValidFullname(Name) != true); + string Email; - do { + do + { Console.Write("Email: "); - Email = Console.ReadLine(); + Email = Console.ReadLine()!; } while (ValidationLogic.IsValidEmail(Email) != true); string Date; - do { + 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()!; - string TimeSlot; - do { - Console.Write("Time (00:00): "); - TimeSlot = Console.ReadLine(); + if (!ValidationLogic.IsValidDate(Date)) + { + Console.WriteLine("Veerkde datum. Vul een juiste formaat in: DD-MM-JJJJ."); + } + 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[] { $"{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; - do { + + string Amt_People_Check; + 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("Tafel nummers"); - List Tables = new List (); - while (true) { - string Table_number = Console.ReadLine(); - if (Table_number != "") { - try { - Tables.Add(Table_number); - } catch { - Console.WriteLine("Toevoegen mislukt, voer tafel nummers in!"); - } - } else { - break; + Amt_People_Check = Console.ReadLine()!; + } while (ValidationLogic.IsNumeric(Amt_People_Check) != 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) + { + if (table.Length > 1) + { + string tableCorrect; + tableCorrect = table.Remove(0, 1); + CorrectedTables.Add(tableCorrect); } + 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; + 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)); - 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)); + ReservationModel? ReservationObject = ReservationLogic.GetReservation(Convert.ToString(ID)); - if (ReservationObject == null) { + if (ReservationObject == null) + { Console.WriteLine("Reservatie niet gevonden!"); return; } @@ -202,29 +387,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(); + 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 diff --git a/Presentation/Show.cs b/Presentation/Show.cs index 3c03c3b..1f3c487 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 ......2x Voorgerecht, 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); @@ -24,10 +19,15 @@ 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; case 1: + // print the information + informatie(menu.Gangen); // 3 gangen menu Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, includePrice: true); @@ -35,17 +35,34 @@ public static void Menu() Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, includePrice: true); + 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; default: + // print the information + informatie(menu.Gangen); // 4 gangen 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); + 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; @@ -56,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 ......2x Voorgerecht, 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); @@ -75,10 +87,15 @@ 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; case 1: + // print the information + informatie(menu.Gangen); // 3 gangen menu Console.WriteLine("\nVoorgerecht:"); DisplayMenuItems(menu.Starters, username, id, includePrice: true); @@ -86,17 +103,34 @@ 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("\nWijn:"); + DisplayMenuItems(menu.Wijn, username, id, includePrice: false); + Console.WriteLine("\nDrinks:"); 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); + Console.WriteLine("\nSoepen:"); + DisplayMenuItems(menu.Soups, username, id, includePrice: true); + Console.WriteLine("\nHoofdgerecht:"); DisplayMenuItems(menu.Mains, username, id, includePrice: true); + 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; @@ -104,17 +138,42 @@ 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")); + } + else if (menu.Name == "Wijn arrangement") + { + Console.WriteLine($"{menu.Name} kost {menu.Price.ToString("F2")}"); + } + } + } private static void DisplayMenuItems(List items, bool includePrice) { foreach (MenuItem item in items) { 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, '.')); } } } @@ -124,25 +183,30 @@ 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); } } } + // // mehtod return's Gangen menu in list + // private static List GetGangenMenu(List items, bool includePrice) + // { + + // } } 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); - 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"]); diff --git a/Presentation/UserLogin.cs b/Presentation/UserLogin.cs index b812f1b..cf020c9 100644 --- a/Presentation/UserLogin.cs +++ b/Presentation/UserLogin.cs @@ -2,62 +2,81 @@ 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 ?? "N/A"}", $"Wachtwoord: {new string('*', password?.Length ?? 0)}", "", "Login", "Annuleren"); + if (selectedClass == 0) + { + Console.WriteLine("Graag uw email invullen."); + email = Console.ReadLine() ?? string.Empty; + } + else if (selectedClass == 1) + { + Console.WriteLine("Graag uw wachtwoord invullen."); + password = Console.ReadLine() ?? string.Empty; + } + else if (selectedClass == 4) + { + Menu.Start(); + } + else if (selectedClass == 3 && email != null && password != null) + { + 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 + } + if (persoon != null) + { + Menu.Continue(persoon); + } + else + { + Console.WriteLine($"Er ging iets fout! je word terug naar de menu gestuurd"); + Menu.Start(); + } + } + else + { + Console.WriteLine("No account found with that email and password"); + System.Threading.Thread.Sleep(1000); + Start(); + } + } } - } } - } } \ No newline at end of file diff --git a/Presentation/UserRegistration.cs b/Presentation/UserRegistration.cs index e8776ce..f19e931 100644 --- a/Presentation/UserRegistration.cs +++ b/Presentation/UserRegistration.cs @@ -6,59 +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() { - Console.WriteLine("Graag hier je email invullen:"); - Email = Console.ReadLine().ToLower(); - if (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && Email != "1") - { - Console.WriteLine("De email heeft niet de juiste syntax, probeer het opnieuw"); - } - } while (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+.[^@\s]+$") && Email != "1"); + Console.WriteLine("Welkom bij de registratiepagina"); + Console.WriteLine("[1] terug naar het startmenu"); - if (Email == "1") - { - Menu.Start(); - return; - } + 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 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()!; - Console.WriteLine("Graag hier je volledige naam invullen:"); - string FullName = Console.ReadLine(); + } 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); - Menu.Start(); - } + 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(); + } } \ No newline at end of file diff --git a/Presentation/WorkerMenu.cs b/Presentation/WorkerMenu.cs new file mode 100644 index 0000000..f34745b --- /dev/null +++ b/Presentation/WorkerMenu.cs @@ -0,0 +1,41 @@ +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", "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(); + Reservation.MakeReservation(); + Start(username, id); + } + else if (selectedClass == 2) + { + // start de locatie class en show detail + Location? location = Location.CreateLocation(); + if (location != null) + { + LocationPresentation.ShowLocation(location); + } + Console.ReadKey(); + Start(username, id); + } + else if (selectedClass == 3) + { + // 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