You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.0 KiB
75 lines
2.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
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);
|
|
CurrentConnectedUser = null;
|
|
}
|
|
|
|
public bool Login(string mail, string password)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|