diff --git a/GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs b/GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs index 628e1ea..4fb44e3 100644 --- a/GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs +++ b/GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs @@ -35,23 +35,103 @@ public partial class PageAdmin : ContentPage */ private async void OnButtonClicked(object sender, EventArgs e) { - string nom = await DisplayPromptAsync("Informations sur le Jeu", "Quel est le Titre ?", placeholder: "GTA VI"); - string sortie = await DisplayPromptAsync("Informations sur le Jeu", "Date de Sortie", placeholder: "JJ/MM/AAAA"); - string plateformes = await DisplayPromptAsync("Informations sur le Jeu", "Plateforme(s), un espace pour séparer", placeholder: "Ex: XOne PC PS5"); - string developpeur = await DisplayPromptAsync("Informations sur le Jeu", "Développeur", placeholder: "Rockstar Games"); - string editeur = await DisplayPromptAsync("Informations sur le Jeu", "Editeur", placeholder: "Take-Two Interactive"); - string note = await DisplayPromptAsync("Informations sur le Jeu", "Note de 0 à 5", maxLength: 1, placeholder: "5"); - int noteInt = Int32.Parse(note); - string nbTelechargement = await DisplayPromptAsync("Informations sur le Jeu", "Nombre de Téléchargements (en milliers, ex: 630k)", placeholder: "630"); - int nbTelechargementInt = Int32.Parse(nbTelechargement); - string genre = await DisplayPromptAsync("Informations sur le Jeu", "Genre(s), un espace pour séparer", placeholder: "Action Aventure"); - string image = await DisplayPromptAsync("Informations sur le Jeu", "Image de couverture (préférez URL finissant par .png)", placeholder: "http://example.com/monimage.png"); - - Jeu adminJeu = new Jeu(nom, sortie, plateformes, developpeur, editeur, noteInt, nbTelechargementInt, genre, image); - AdminManager.AddJeux(adminJeu); - AdminManager.SauvegardeDonnees(); - AdminManager.OnPropertyChanged(nameof(AdminManager.ListJeux)); - - Debug.WriteLine($"Le jeu \"{adminJeu.Nom}\" a été ajouté."); + string nom = string.Empty; + string sortie = string.Empty; + string plateformes = string.Empty; + string developpeur = string.Empty; + string editeur = string.Empty; + string note = string.Empty; + string nbTelechargement = string.Empty; + string genre = string.Empty; + string image = string.Empty; + + int etape = 1; + bool annuler = false; + + while (etape <= 9 && !annuler) + { + switch (etape) + { + case 1: + nom = await DisplayPromptAsync("Informations sur le Jeu [1/9]", "Quel est le Titre ?", accept: "Suivant", cancel: "Annuler", placeholder: "GTA VI"); + if (string.IsNullOrEmpty(nom)) + { + annuler = true; + } + break; + case 2: + sortie = await DisplayPromptAsync("Informations sur le Jeu [2/9]", "Date de Sortie", accept: "Suivant", cancel: "Annuler", placeholder: "JJ/MM/AAAA"); + if (string.IsNullOrEmpty(sortie)) + { + annuler = true; + } + break; + case 3: + plateformes = await DisplayPromptAsync("Informations sur le Jeu [3/9]", "Plateforme(s), un espace pour séparer", accept: "Suivant", cancel: "Annuler", placeholder: "Ex: XOne PC PS5"); + if (string.IsNullOrEmpty(plateformes)) + { + annuler = true; + } + break; + case 4: + developpeur = await DisplayPromptAsync("Informations sur le Jeu [4/9]", "Développeur", accept: "Suivant", cancel: "Annuler", placeholder: "Rockstar Games"); + if (string.IsNullOrEmpty(developpeur)) + { + annuler = true; + } + break; + case 5: + editeur = await DisplayPromptAsync("Informations sur le Jeu [5/9]", "Editeur", accept: "Suivant", cancel: "Annuler", placeholder: "Take-Two Interactive"); + if (string.IsNullOrEmpty(editeur)) + { + annuler = true; + } + break; + case 6: + note = await DisplayPromptAsync("Informations sur le Jeu [6/9]", "Note de 0 à 5", accept: "Suivant", cancel: "Annuler", maxLength: 1, placeholder: "5"); + if (string.IsNullOrEmpty(note)) + { + annuler = true; + } + break; + case 7: + nbTelechargement = await DisplayPromptAsync("Informations sur le Jeu [7/9]", "Nombre de Téléchargements (en milliers, ex: 630k)", accept: "Suivant", cancel: "Annuler", placeholder: "630"); + if (string.IsNullOrEmpty(nbTelechargement)) + { + annuler = true; + } + break; + case 8: + genre = await DisplayPromptAsync("Informations sur le Jeu [8/9]", "Genre(s), un espace pour séparer", accept: "Suivant", cancel: "Annuler", placeholder: "Action Aventure"); + if (string.IsNullOrEmpty(genre)) + { + annuler = true; + } + break; + case 9: + image = await DisplayPromptAsync("Informations sur le Jeu [9/9]", "Image de couverture (préférez URL finissant par .png)", accept: "Terminer", cancel: "Annuler", placeholder: "http://example.com/monimage.png"); + if (string.IsNullOrEmpty(image)) + { + annuler = true; + } + break; + } + + etape++; + } + + if (!annuler) + { + Jeu adminJeu = new Jeu(nom, sortie, plateformes, developpeur, editeur, Convert.ToInt32(note), Convert.ToInt32(nbTelechargement), genre, image); + AdminManager.AddJeux(adminJeu); + AdminManager.SauvegardeDonnees(); + AdminManager.OnPropertyChanged(nameof(AdminManager.ListJeux)); + + Debug.WriteLine($"Le jeu \"{adminJeu.Nom}\" a été ajouté."); + } + else + { + Debug.WriteLine("Annulation de l'ajout du jeu."); + } } } \ No newline at end of file diff --git a/GameAtlas/GameAtlas/Views/PageJeu.xaml.cs b/GameAtlas/GameAtlas/Views/PageJeu.xaml.cs index b68fede..caffc84 100644 --- a/GameAtlas/GameAtlas/Views/PageJeu.xaml.cs +++ b/GameAtlas/GameAtlas/Views/PageJeu.xaml.cs @@ -1,5 +1,8 @@ using GameAtlas.Models; using System.Diagnostics; +using CommunityToolkit.Maui.Alerts; +using CommunityToolkit.Maui.Core; +using Font = Microsoft.Maui.Font; namespace GameAtlas.Views; @@ -92,7 +95,8 @@ public partial class PageJeu : ContentPage } else { - await DisplayAlert("Erreur", "Vous devez vous connecter pour faire cela !", "Ok"); + //await DisplayAlert("Erreur", "Vous devez vous connecter pour faire cela !", "Ok"); + Alert(); } } @@ -100,4 +104,27 @@ public partial class PageJeu : ContentPage { await Navigation.PopAsync(); } + + async void Alert() + { + CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); + + var snackbarOptions = new SnackbarOptions + { + BackgroundColor = Colors.Red, + TextColor = Colors.White, + ActionButtonTextColor = Colors.White, + Font = Font.SystemFontOfSize(14), + ActionButtonFont = Font.SystemFontOfSize(16), + CharacterSpacing = 0 + }; + + string text = "Vous devez être connecté pour effectué cette action."; + string actionButtonText = "OK"; + TimeSpan duration = TimeSpan.FromSeconds(3); + + var snackbar = Snackbar.Make(text, null, actionButtonText, duration, snackbarOptions); + + await snackbar.Show(cancellationTokenSource.Token); + } } \ No newline at end of file