done first ver. of MasterManager

pull/48/head
Alexandre AGOSTINHO 2 years ago
parent 31fec8e200
commit 34de5e0b85

@ -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();
}
}
}

Loading…
Cancel
Save