working on MasterManager

pull/48/head
Alexandre AGOSTINHO 2 years ago
parent b6729c5f68
commit 9eef461a44

@ -3,7 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu
{ {
internal class ConnectionMenu : Entry internal class ConnectionMenu : Entry

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
internal abstract partial class Entry internal abstract partial class Entry
{ {

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
namespace ConsoleApp.Menu
namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// Define an Entry menu. /// Define an Entry menu.

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// Define a console menu with element selection. /// Define a console menu with element selection.

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// Define a selection menu. /// Define a selection menu.
@ -44,7 +44,7 @@ namespace ConsoleApp.Menu
{ {
_currentLine = value; _currentLine = value;
if (_currentLine <= 0) _currentLine = 0; if (_currentLine <= 0) _currentLine = 0;
else if (_currentLine >= _selectList.Count) _currentLine = _selectList.Count-1; else if (_currentLine >= _selectList.Count) _currentLine = _selectList.Count - 1;
} }
} }
@ -75,7 +75,7 @@ namespace ConsoleApp.Menu
/// </summary> /// </summary>
/// <param name="title">The title of the menu.</param> /// <param name="title">The title of the menu.</param>
/// <param name="selections">The selections of the menu.</param> /// <param name="selections">The selections of the menu.</param>
protected Menu(string title, params Selector<T>[] selections ) : this(title) protected Menu(string title, params Selector<T>[] selections) : this(title)
{ {
if (selections == null || selections.Length == 0) if (selections == null || selections.Length == 0)
{ {

@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// Define a Plain text menu. /// Define a Plain text menu.
@ -36,16 +36,16 @@ namespace ConsoleApp.Menu
public StringBuilder InputStr { get; set; } public StringBuilder InputStr { get; set; }
public void DisableWriteMode() public void DisableWriteMode()
{ {
// Plain text does not need to do anything for this. // Plain text does not need to do anything for this.
} }
public void EnableWriteMode() public void EnableWriteMode()
{ {
// Plain text does not need to do anything for this. // Plain text does not need to do anything for this.
} }
public void SelectNext() public void SelectNext()
{ {
// Plain text does not need to do anything for this. // Plain text does not need to do anything for this.
} }
public void SelectPrevious() public void SelectPrevious()
{ {

@ -7,7 +7,7 @@ using System.Reflection.Emit;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// The selector of a menu. /// The selector of a menu.
@ -22,7 +22,8 @@ namespace ConsoleApp.Menu
/// <summary> /// <summary>
/// The string that are displayed on the menu. /// The string that are displayed on the menu.
/// </summary> /// </summary>
public string Line { public string Line
{
get => _line; get => _line;
private set private set
{ {
@ -57,7 +58,7 @@ namespace ConsoleApp.Menu
{ {
if (other == null) return false; if (other == null) return false;
if (other == this) return true; if (other == this) return true;
return other.Line.Equals(this.Line); return other.Line.Equals(Line);
} }
public override bool Equals(object? obj) public override bool Equals(object? obj)

@ -5,7 +5,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu
{ {
/// <summary> /// <summary>

@ -4,7 +4,7 @@ using System.Linq;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
using Model; using Model;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
namespace ConsoleApp namespace ConsoleApp
{ {
@ -23,7 +24,7 @@ namespace ConsoleApp
/// <summary> /// <summary>
/// Each menu called are push in this stack. Then, to return back, we pop this stack to retrive the previous menu. /// Each menu called are push in this stack. Then, to return back, we pop this stack to retrive the previous menu.
/// </summary> /// </summary>
public Stack<Menu.IMenu> MenuCallStack { get; set; } public Stack<IMenu> MenuCallStack { get; set; }
#endregion #endregion
#region Constructors #region Constructors
@ -32,11 +33,11 @@ namespace ConsoleApp
/// </summary> /// </summary>
/// <param name="dataManager">The data manager needed by the menus inside.</param> /// <param name="dataManager">The data manager needed by the menus inside.</param>
/// <param name="firstMenu">The starting menu, the first that will be push on the call stack.</param> /// <param name="firstMenu">The starting menu, the first that will be push on the call stack.</param>
public MenuManager(DataManager dataManager, Menu.IMenu firstMenu) public MenuManager(DataManager dataManager, IMenu firstMenu)
{ {
DataManager = dataManager; DataManager = dataManager;
MenuCallStack = new Stack<Menu.IMenu>(); MenuCallStack = new Stack<IMenu>();
MenuCallStack.Push(firstMenu); MenuCallStack.Push(firstMenu);
} }
@ -55,7 +56,7 @@ namespace ConsoleApp
public void Loop() public void Loop()
{ {
ConsoleKeyInfo cki; ConsoleKeyInfo cki;
Menu.IMenu menuOnHead; IMenu menuOnHead;
do do
{ {
menuOnHead = MenuCallStack.Peek(); menuOnHead = MenuCallStack.Peek();
@ -72,7 +73,7 @@ namespace ConsoleApp
menuOnHead.SelectPrevious(); menuOnHead.SelectPrevious();
break; break;
case ConsoleKey.Enter: case ConsoleKey.Enter:
Menu.IMenu? retMenu = menuOnHead.Return(); IMenu? retMenu = menuOnHead.Return();
if (retMenu is null) MenuCallStack.Pop(); if (retMenu is null) MenuCallStack.Pop();
else MenuCallStack.Push(retMenu); else MenuCallStack.Push(retMenu);
break; break;

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Managers
{
public class MasterManager
{
public static User? CurrentConnectedUser;
public static RecipeCollection? Recipes;
public static List<User>? Users;
public DataManager DataMgr { get; private set; }
public MasterManager(IDataManager dataManager)
{
DataMgr = new DataManager(dataManager);
Recipes = DataMgr.GetRecipes("all recipes");
Users = DataMgr.GetUsers();
CurrentConnectedUser = null;
}
public bool LogIn(string mail, string password)
{
if (Users is null)
throw new ArgumentNullException();
User user = (User)(from u in Users
where u.Mail == mail
select u);
}
}
}

@ -131,7 +131,6 @@ namespace Model
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
@ -159,7 +158,5 @@ namespace Model
#endregion #endregion
} }
} }

Loading…
Cancel
Save