|
|
@ -9,14 +9,38 @@ using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Model.Managers
|
|
|
|
namespace Model.Managers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The Main manager of the model.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public class MasterManager
|
|
|
|
public class MasterManager
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
#region Attributes & Properties
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The currently connected user. 'null' if no user is connected.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public User? CurrentConnectedUser { get; private set; }
|
|
|
|
public User? CurrentConnectedUser { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The collection of all recipes loaded.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public RecipeCollection Recipes { get; private set; }
|
|
|
|
public RecipeCollection Recipes { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The collection of all users loaded.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public List<User> Users { get; private set; }
|
|
|
|
public List<User> Users { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The data manager for load, save, export and import data.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public DataManager DataMgr { get; private set; }
|
|
|
|
public DataManager DataMgr { get; private set; }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Constructor of the MasterManager.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="dataManager">The serializer for the data.</param>
|
|
|
|
public MasterManager(IDataManager dataManager)
|
|
|
|
public MasterManager(IDataManager dataManager)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DataMgr = new DataManager(dataManager);
|
|
|
|
DataMgr = new DataManager(dataManager);
|
|
|
@ -24,7 +48,16 @@ namespace Model.Managers
|
|
|
|
Recipes = DataMgr.GetRecipes("all recipes");
|
|
|
|
Recipes = DataMgr.GetRecipes("all recipes");
|
|
|
|
Users = DataMgr.GetUsers();
|
|
|
|
Users = DataMgr.GetUsers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Log in an user. Test if the log in information are correct then connect the user.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="mail">The user's mail</param>
|
|
|
|
|
|
|
|
/// <param name="password">The user's password.</param>
|
|
|
|
|
|
|
|
/// <returns>True if the user was correctly connected, false if there is something wrong.</returns>
|
|
|
|
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
public bool Login(string mail, string password)
|
|
|
|
public bool Login(string mail, string password)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Users is null || Users.Count == 0)
|
|
|
|
if (Users is null || Users.Count == 0)
|
|
|
@ -45,6 +78,10 @@ namespace Model.Managers
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Log out an user.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns>True if the user is correctly diconnected, false otherwise.</returns>
|
|
|
|
public bool Logout()
|
|
|
|
public bool Logout()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (CurrentConnectedUser is null)
|
|
|
|
if (CurrentConnectedUser is null)
|
|
|
@ -54,6 +91,11 @@ namespace Model.Managers
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Register an user.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="newuser">The new user to add in the database.</param>
|
|
|
|
|
|
|
|
/// <returns>False if there is a problem with the registerement, true otherwise.</returns>
|
|
|
|
public bool Register(User newuser)
|
|
|
|
public bool Register(User newuser)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -71,14 +113,23 @@ namespace Model.Managers
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Add a recipe to the database.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="recipe">The recipe to add.</param>
|
|
|
|
public void AddRecipe(Recipe recipe)
|
|
|
|
public void AddRecipe(Recipe recipe)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DataMgr.Data[nameof(Recipe)].Add(recipe);
|
|
|
|
DataMgr.Data[nameof(Recipe)].Add(recipe);
|
|
|
|
Recipes = DataMgr.GetRecipes();
|
|
|
|
Recipes = DataMgr.GetRecipes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Get the current connected user's personal recipes.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns>The current connected user's personal recipes.</returns>
|
|
|
|
public RecipeCollection GetCurrentUserRecipes()
|
|
|
|
public RecipeCollection GetCurrentUserRecipes()
|
|
|
|
=> new RecipeCollection("User recipes",
|
|
|
|
=> new RecipeCollection("User recipes",
|
|
|
|
DataMgr.GetRecipes().FindAll(r => r.AuthorMail == CurrentConnectedUser?.Mail).ToArray());
|
|
|
|
DataMgr.GetRecipes().FindAll(r => r.AuthorMail == CurrentConnectedUser?.Mail).ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|