diff --git a/MCTG/ConsoleApp/Menu/MainMenu.cs b/MCTG/ConsoleApp/Menu/MainMenu.cs index 9bdc7ad..5f32956 100644 --- a/MCTG/ConsoleApp/Menu/MainMenu.cs +++ b/MCTG/ConsoleApp/Menu/MainMenu.cs @@ -1,25 +1,25 @@ -using Model; -using DataPersistence; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Model; +using DataPersistence; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using ConsoleApp.Menu.Core; -namespace ConsoleApp.Menu -{ - /// - /// Main menu of the console. Contain the first interaction menus. - /// - internal class MainMenu : Menu - { - public MainMenu(DataManager dataMgr) - : base("Main menu", - new Selector( - new SearcherRecipe(new RecipeCollection("search", dataMgr.Data[nameof(Recipe)].Cast().ToArray())), "Recipe search"), - new Selector( - new ConnectionMenu(), "Connection")) - { } - } -} +namespace ConsoleApp.Menu +{ + /// + /// Main menu of the console. Contain the first interaction menus. + /// + internal class MainMenu : Menu + { + public MainMenu(DataManager dataMgr) + : base("Main menu", + new Selector( + new SearcherRecipe(new RecipeCollection("search", dataMgr.Data[nameof(Recipe)].Cast().ToArray())), "Recipe search"), + new Selector( + new ConnectionMenu(), "Connection")) + { } + } +} diff --git a/MCTG/Model/Managers/MasterManager.cs b/MCTG/Model/Managers/MasterManager.cs index a093e71..9f39d9f 100644 --- a/MCTG/Model/Managers/MasterManager.cs +++ b/MCTG/Model/Managers/MasterManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -23,14 +24,52 @@ namespace Model.Managers CurrentConnectedUser = null; } - public bool LogIn(string mail, string password) + public bool Login(string mail, string password) { - if (Users is null) - throw new ArgumentNullException(); + if (Users is null || Users.Count == 0) + throw new ArgumentNullException("There is no users registred."); User user = (User)(from u in Users where u.Mail == mail select u); + + if (user is null || !user.psswMgr.VerifyPassword(user.Password, password)) + return false; + + CurrentConnectedUser = user; + return true; + } + + public bool Logout() + { + if (CurrentConnectedUser is null) + return false; + + CurrentConnectedUser = null; + return true; + } + + public bool Register(User newuser) + { + try + { + User user = newuser; + DataMgr.Data[nameof(User)].Add(user); + Users = DataMgr.GetUsers(); + } + catch (ArgumentException e) + { + Debug.WriteLine(e.Message); + return false; + } + + return true; + } + + public void AddRecipe(Recipe recipe) + { + DataMgr.Data[nameof(Recipe)].Add(recipe); + Recipes = DataMgr.GetRecipes(); } } }