1+ using MatchingGame . Clases ;
2+ using MatchingGame . Vistas . HomePage ;
3+ using Newtonsoft . Json ;
4+ using System ;
5+ using System . Collections . Generic ;
6+ using System . Linq ;
7+ using System . Net . Http ;
8+ using System . Text ;
9+ using System . Threading . Tasks ;
10+
11+ using Xamarin . Forms ;
12+ using Xamarin . Forms . Xaml ;
13+
14+ namespace MatchingGame . Vistas . ModalPage
15+ {
16+ [ XamlCompilation ( XamlCompilationOptions . Compile ) ]
17+ public partial class ProfilePage : ContentPage
18+ {
19+ public ProfilePage ( )
20+ {
21+ InitializeComponent ( ) ;
22+ if ( Application . Current . Properties . ContainsKey ( "Photo" )
23+ && Application . Current . Properties . ContainsKey ( "Name" )
24+ && Application . Current . Properties . ContainsKey ( "Email" )
25+ && Application . Current . Properties . ContainsKey ( "Score" ) )
26+ {
27+ SelectAvatar . Source = Application . Current . Properties [ "Photo" ] as string ;
28+ Name . Text = Application . Current . Properties [ "Name" ] as string ;
29+ Email . Text = Application . Current . Properties [ "Email" ] as string ;
30+ Score . Text = Application . Current . Properties [ "Score" ] . ToString ( ) ;
31+ MaxLevel . Text = Application . Current . Properties [ "MaxLevel" ] . ToString ( ) ;
32+ GetMyPositionLaderboard ( ) ;
33+ }
34+ }
35+
36+ public async void GetMyPositionLaderboard ( )
37+ {
38+ try
39+ {
40+ Uri RequestUri = new ( "https://matchinggame.vercel.app/api/matching-game" ) ;
41+ var client = new HttpClient ( ) ;
42+ HttpResponseMessage response = await client . GetAsync ( RequestUri ) ;
43+ if ( response . IsSuccessStatusCode )
44+ {
45+ var content = await response . Content . ReadAsStringAsync ( ) ;
46+ User [ ] users = JsonConvert . DeserializeObject < User [ ] > ( content ) ;
47+
48+ if ( Application . Current . Properties . ContainsKey ( "Email" ) )
49+ {
50+ var email = Application . Current . Properties [ "Email" ] as string ;
51+ for ( int i = 0 ; i < users . Length ; i ++ )
52+ {
53+ if ( users [ i ] . email == email )
54+ {
55+ Position . Text = ( i + 1 ) . ToString ( ) ;
56+ }
57+ }
58+ }
59+ }
60+ }
61+ catch ( Exception error )
62+ {
63+ await DisplayAlert ( "Error" , error . Message , "Cancelar" ) ;
64+ }
65+ }
66+
67+ private async void Logout_Clicked ( object sender , EventArgs e )
68+ {
69+ Application . Current . Properties . Remove ( "Token" ) ;
70+ Application . Current . Properties . Remove ( "Name" ) ;
71+ Application . Current . Properties . Remove ( "Email" ) ;
72+ Application . Current . Properties . Remove ( "Password" ) ;
73+ Application . Current . Properties . Remove ( "Score" ) ;
74+ Application . Current . Properties . Remove ( "Photo" ) ;
75+ Application . Current . Properties . Remove ( "Id" ) ;
76+ Application . Current . Properties . Remove ( "MaxLevel" ) ;
77+
78+ await Application . Current . SavePropertiesAsync ( ) ;
79+ await Navigation . PushAsync ( new Home ( ) ) ;
80+ }
81+
82+ protected override bool OnBackButtonPressed ( )
83+ {
84+ PromptForExit ( ) ;
85+ return true ;
86+ }
87+
88+ private async void PromptForExit ( )
89+ {
90+ await Navigation . PopToRootAsync ( ) ;
91+ }
92+ }
93+ }
0 commit comments