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.
ConsEco/Sources/Modele/Manager.cs

233 lines
6.1 KiB

using System.Collections.ObjectModel;
using System.ComponentModel;
2 years ago
using System.Diagnostics;
namespace Model
{
/// <summary>
/// Permet de faire le lien entre le modèle et la base de donnée..
/// </summary>
public class Manager : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public IPersistanceManager Pers { get; private set; }
public Inscrit User
{
get
{
return user;
}
set
{
if (user != value)
{
user = value;
OnPropertyChanged(nameof(User));
LoadBanque();
}
}
}
private Inscrit user;
public BanqueInscrit SelectedBanque
{
get => selectedBanque;
set
{
if (selectedBanque != value)
{
selectedBanque = value;
2 years ago
OnPropertyChanged(nameof(SelectedBanque));
2 years ago
LoadCompte();
}
}
}
private BanqueInscrit selectedBanque;
public IList<Banque> BanquesDisponibleInApp
{
get => banquesDisponibleInApp;
set
{
if (banquesDisponibleInApp != value)
{
banquesDisponibleInApp = value;
OnPropertyChanged(nameof(BanquesDisponibleInApp));
}
}
}
private IList<Banque> banquesDisponibleInApp;
public Compte SelectedCompte
{
get => selectedCompte;
set
{
if(selectedCompte != value)
{
selectedCompte = value;
OnPropertyChanged(nameof(SelectedCompte));
}
}
}
private Compte selectedCompte;
2 years ago
public IList<BanqueInscrit> ListeDesBanques
{
get => listeDesBanques;
set
{
if (listeDesBanques != value)
{
listeDesBanques = value;
OnPropertyChanged(nameof(ListeDesBanques));
}
}
}
private IList<BanqueInscrit> listeDesBanques = new List<BanqueInscrit>();
2 years ago
//private IList<BanqueInscrit> listeDesBanques = new List<BanqueInscrit>();
/*public ReadOnlyCollection<BanqueInscrit> AllBanque
{
get => allBanque;
set
{
if (allBanque != value)
{
allBanque = value;
OnPropertyChanged(nameof(AllBanque));
}
}
}
private ReadOnlyCollection<BanqueInscrit> allBanque;*/
2 years ago
public List<Compte> ListeDesComptes
{
get => listeDesComptes;
set
{
if (listeDesComptes != value)
{
listeDesComptes = value;
OnPropertyChanged(nameof(ListeDesComptes));
}
}
}
private List<Compte> listeDesComptes = new List<Compte>();
2 years ago
//public ReadOnlyCollection<Compte> AllCompte { get; private set; }
public Manager(IPersistanceManager persistance)
{
2 years ago
//AllBanque = new ReadOnlyCollection<BanqueInscrit>(listeDesBanques);
//AllCompte = new ReadOnlyCollection<Compte>(listeDesComptes);
Pers = persistance;
}
2 years ago
public async void LoadCompte()
{
2 years ago
ListeDesComptes.Clear();
if(SelectedBanque == null)
{
throw new ArgumentNullException("Vous n'avez pas de banque disponible");
}
try
{
IList<Compte> comptes = await Pers.RecupererCompte(SelectedBanque);
2 years ago
ListeDesComptes.AddRange(comptes);
foreach (Compte compte in ListeDesComptes)
{
compte.LesPla = await Pers.RecupererPlanification(compte);
compte.LesOpe = await Pers.RecupererOperation(compte);
compte.LesEch = await Pers.RecupererEcheance(compte);
}
2 years ago
2 years ago
SelectedCompte = ListeDesComptes.FirstOrDefault();
}
catch(Exception exception)
{
Debug.WriteLine(exception.Message);
}
}
public async void LoadBanque()
{
try
{
2 years ago
ListeDesBanques = await Pers.RecupererBanques(User);
SelectedBanque = ListeDesBanques.FirstOrDefault();
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
}
public async void LoadBanqueDispo()
{
try
{
BanquesDisponibleInApp = await Pers.RecupererBanquesDisponible();
}catch(Exception exception)
{
Debug.WriteLine(exception.Message);
}
}
2 years ago
void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
2 years ago
public bool CompareHash(string mdpBdd, string mdpSent)
{
return Hash.IsEqualHash(mdpBdd, mdpSent);
}
public void deconnexion()
{
User = null;
}
/*public async void LoadBanques()
{
User.LesBanques = await Pers.RecupererBanques(User);
2 years ago
BanquesDisponibleInApp = await Pers.RecupererBanquesDisponible();
}*/
2 years ago
public async Task<string> getPassword(string email)
{
2 years ago
Inscrit inscrit = await Pers.RecupererInscrit(email);
return inscrit.Mdp;
}
2 years ago
public async void createUser(string mail)
{
2 years ago
User = await Pers.RecupererInscrit(mail);
}
2 years ago
}
}