diff --git a/Sources/API/routes/Banque.php b/Sources/API/routes/Banque.php index 9d7ce97..cd12389 100644 --- a/Sources/API/routes/Banque.php +++ b/Sources/API/routes/Banque.php @@ -45,7 +45,7 @@ $app->get('/Banque/', function(Request $request, Response $response){ $app->post('/Banque/FromId/', function(Request $request, Response $response,array $args){ $id = $request->getParsedBody()["id"]; - $query = 'SELECT * FROM Banque WHERE nom IN (SELECT nomBanque FROM InscrBanque WHERE idInscrit=:id)'; + $query = 'SELECT id, nomBanque FROM InscrBanque WHERE idInscrit=:id'; try{ $db = new Database(); diff --git a/Sources/Data/ClientAPI.cs b/Sources/Data/ClientAPI.cs index 6f9cf0b..e77bdcb 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -155,14 +155,14 @@ namespace Data } } - public static async Task> GetBanqueAsync(string id) + public static async Task> GetBanqueAsync(string id) { var dataBody = new Dictionary { { "id", id } }; HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_BANQUES_INSCRIT_DATA_URL, dataBody); if (reponse.IsSuccessStatusCode) { - return JsonConvert.DeserializeObject>(await reponse.Content.ReadAsStringAsync()); + return JsonConvert.DeserializeObject>(await reponse.Content.ReadAsStringAsync()); } else { diff --git a/Sources/Data/PersAPI.cs b/Sources/Data/PersAPI.cs index b7858a8..ee7c4d2 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -56,7 +56,7 @@ namespace Data { return await ClientAPI.DeleteBanqueInscritAsync(banque.Nom, inscrit.Id.ToString()); } - public async Task> RecupererBanques(Inscrit inscrit) + public async Task> RecupererBanques(Inscrit inscrit) { return await ClientAPI.GetBanqueAsync(inscrit.Id.ToString()); } @@ -75,9 +75,9 @@ namespace Data { return await ClientAPI.DeleteCompteInscritAsync(compte.Nom, inscrit.Id.ToString()); } - public async Task> RecupererCompte(Banque banque, Inscrit inscrit) + public async Task> RecupererCompte(BanqueInscrit banque) { - return await ClientAPI.GetCompteAsync(inscrit.Id.ToString()); + return await ClientAPI.GetCompteAsync(banque.Id.ToString()); } diff --git a/Sources/Data/PersStub.cs b/Sources/Data/PersStub.cs index f4b5cde..c3923e3 100644 --- a/Sources/Data/PersStub.cs +++ b/Sources/Data/PersStub.cs @@ -201,7 +201,7 @@ namespace Data throw new NotImplementedException(); } - public Task> RecupererBanques(Inscrit inscrit) + public Task> RecupererBanques(Inscrit inscrit) { throw new NotImplementedException(); } @@ -211,7 +211,7 @@ namespace Data throw new NotImplementedException(); } - public Task> RecupererCompte(Banque banque, Inscrit inscrit) + public Task> RecupererCompte(BanqueInscrit banque) { throw new NotImplementedException(); } diff --git a/Sources/IHM/Mobile/AjoutBanques.xaml.cs b/Sources/IHM/Mobile/AjoutBanques.xaml.cs index 8b70e66..8e082b3 100644 --- a/Sources/IHM/Mobile/AjoutBanques.xaml.cs +++ b/Sources/IHM/Mobile/AjoutBanques.xaml.cs @@ -11,7 +11,7 @@ public partial class AjoutBanques : ContentPage { InitializeComponent(); BindingContext = Mgr; - Mgr.LoadBanques(); + //Mgr.LoadBanques(); if (OperatingSystem.IsIOS()) { boutonRetour.IsVisible = true; @@ -71,7 +71,7 @@ public partial class AjoutBanques : ContentPage } } - Mgr.User.LesBanques = await Mgr.Pers.RecupererBanques(Mgr.User); + //Mgr.User.LesBanques = await Mgr.Pers.RecupererBanques(Mgr.User); await Navigation.PopModalAsync(); } } diff --git a/Sources/IHM/Mobile/GestionBanques.xaml.cs b/Sources/IHM/Mobile/GestionBanques.xaml.cs index 6d1001a..04681a8 100644 --- a/Sources/IHM/Mobile/GestionBanques.xaml.cs +++ b/Sources/IHM/Mobile/GestionBanques.xaml.cs @@ -11,7 +11,7 @@ public partial class GestionBanques : ContentPage { InitializeComponent(); BindingContext= Mgr; - Mgr.LoadBanques(); + //Mgr.LoadBanques(); if (OperatingSystem.IsIOS()) { boutonRetour.IsVisible = true; diff --git a/Sources/IHM/Mobile/MainPage.xaml.cs b/Sources/IHM/Mobile/MainPage.xaml.cs index 5521080..c9aedb4 100644 --- a/Sources/IHM/Mobile/MainPage.xaml.cs +++ b/Sources/IHM/Mobile/MainPage.xaml.cs @@ -28,7 +28,7 @@ namespace IHM.Mobile Mgr.createUser(EntryMail.Text); await Navigation.PopModalAsync(); - Mgr.LoadBanques(); + //Mgr.LoadBanques(); } else { diff --git a/Sources/Modele/Banque.cs b/Sources/Modele/Banque.cs index 7e1898f..eb9afc1 100644 --- a/Sources/Modele/Banque.cs +++ b/Sources/Modele/Banque.cs @@ -11,6 +11,7 @@ namespace Model public class Banque : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; + public string Nom { get; private set; } /// @@ -49,10 +50,10 @@ namespace Model ListeDesComptes = lescomptes; } - /* public Banque() - { - } -*/ + /* public Banque() + { + } + */ void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public void AjouterCompte(Compte compte) { diff --git a/Sources/Modele/BanqueInscrit.cs b/Sources/Modele/BanqueInscrit.cs new file mode 100644 index 0000000..c43c772 --- /dev/null +++ b/Sources/Modele/BanqueInscrit.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + public class BanqueInscrit + { + public int Id { get; private set; } + public string Name { get; private set; } + + [JsonConstructor] + public BanqueInscrit(int id, string name) + { + Id = id; + Name = name; + } + + public override string ToString() + { + return Id + " " + Name; + } + } +} diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index e38d11e..44142d5 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -22,14 +22,14 @@ namespace Model //actions sur les banques Task AjouterBanque(Banque banque, Inscrit inscrit); Task SupprimerBanque(Banque banque, Inscrit inscrit); - Task> RecupererBanques(Inscrit inscrit); + Task> RecupererBanques(Inscrit inscrit); Task> RecupererBanquesDisponible(); //actions sur les comptes Task AjouterCompte(Compte compte, Inscrit inscrit); Task SupprimerCompte(Compte compte, Inscrit inscrit); - Task> RecupererCompte(Banque banque, Inscrit inscrit); + Task> RecupererCompte(BanqueInscrit banque); //actions sur les Opérations diff --git a/Sources/Modele/Manager.cs b/Sources/Modele/Manager.cs index 0a5b934..1fc6c75 100644 --- a/Sources/Modele/Manager.cs +++ b/Sources/Modele/Manager.cs @@ -26,12 +26,12 @@ namespace Model { user = value; OnPropertyChanged(nameof(User)); - + LoadBanque(); } } } - public Banque SelectedBanque + public BanqueInscrit SelectedBanque { get => selectedBanque; set @@ -43,7 +43,7 @@ namespace Model } } } - private Banque selectedBanque; + private BanqueInscrit selectedBanque; public IList BanquesDisponibleInApp { get => banquesDisponibleInApp; @@ -75,8 +75,8 @@ namespace Model private Compte selectedCompte; - private IList listeDesBanques = new List(); - public ReadOnlyCollection AllBanque { get; private set; } + private IList listeDesBanques = new List(); + public ReadOnlyCollection AllBanque { get; private set; } private List listeDesComptes = new List(); @@ -86,7 +86,7 @@ namespace Model public Manager(IPersistanceManager persistance) { - AllBanque = new ReadOnlyCollection(listeDesBanques); + AllBanque = new ReadOnlyCollection(listeDesBanques); AllCompte = new ReadOnlyCollection(listeDesComptes); Pers = persistance; } @@ -97,16 +97,17 @@ namespace Model public async void LoadCompte() { + listeDesComptes.Clear(); - if(SelectedBanque == null || SelectedCompte == null) + if(SelectedBanque == null) { throw new ArgumentNullException("Vous n'avez pas de banque disponible"); } try { - IList comptes = await Pers.RecupererCompte(SelectedBanque, User); + IList comptes = await Pers.RecupererCompte(SelectedBanque); listeDesComptes.AddRange(comptes); } catch(Exception exception) @@ -130,6 +131,8 @@ namespace Model } + + SelectedCompte = listeDesComptes.FirstOrDefault(); } @@ -138,12 +141,14 @@ namespace Model try { listeDesBanques = await Pers.RecupererBanques(User); - }catch(Exception exception) + SelectedBanque = listeDesBanques.FirstOrDefault(); + + } + catch (Exception exception) { Debug.WriteLine(exception.Message); } - SelectedBanque = listeDesBanques.First(); } public async void LoadBanqueDispo() @@ -173,11 +178,11 @@ namespace Model User = null; } - public async void LoadBanques() + /*public async void LoadBanques() { User.LesBanques = await Pers.RecupererBanques(User); BanquesDisponibleInApp = await Pers.RecupererBanquesDisponible(); - } + }*/ public async Task getPassword(string email) { diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 1f2f1d3..496f0b1 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -2,6 +2,7 @@ using Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Syncfusion.Maui.DataSource.Extensions; using System.Net.Http.Headers; using System.Security.Principal; using System.Xml.Linq; @@ -87,8 +88,8 @@ foreach (Banque b in banques) Console.WriteLine("\n--------\n"); -IList banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult(); -foreach (Banque b in banquesId1) +IList banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult(); +foreach (BanqueInscrit b in banquesId1) { Console.WriteLine(b); } @@ -101,7 +102,7 @@ Console.WriteLine("Add banque for user : " + rrrr + "\n"); Console.WriteLine("\n----Verif----\n"); banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult(); -foreach (Banque b in banquesId1) +foreach (BanqueInscrit b in banquesId1) { Console.WriteLine(b); } @@ -114,7 +115,7 @@ Console.WriteLine("Del banque for user : " + rrrrrr + "\n"); Console.WriteLine("\n----Verif----\n"); banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult(); -foreach (Banque b in banquesId1) +foreach (BanqueInscrit b in banquesId1) { Console.WriteLine(b); } @@ -245,4 +246,15 @@ echeances = ClientAPI.GetEcheanceAsync("1").GetAwaiter().GetResult(); foreach (Echeance e in echeances) { Console.WriteLine(e); -} \ No newline at end of file +} + + +Console.WriteLine("errr"); + +// test pers API +IPersistanceManager Pers = new PersAPI(); + +IList bla = Pers.RecupererCompte(new BanqueInscrit(34,"BANQUE POSTALE")).GetAwaiter().GetResult(); +bla.ForEach(c=> Console.WriteLine(c)); + +