async void CheckShop(object sender, System.EventArgs e) { Button btn = (Button)sender; int idShop = Convert.ToInt32(btn.ClassId.ToString()); Device.BeginInvokeOnMainThread(async() => { IPizzaApiService service = DependencyService.Get <IPizzaApiService>(); Response <List <ShopItem> > response = await service.ListShops(); Console.WriteLine($"Appel HTTP : {response.IsSuccess}"); if (response.IsSuccess) { Console.WriteLine($"Appel HTTP : {response.Data.Count}"); Shops = new ObservableCollection <ShopItem>(response.Data); } foreach (ShopItem s in Shops) { if (s.Id == idShop) { await Navigation.PushAsync(new PizzaListPage(s.Name, s.Address, idShop)); } } }); }
public async void SetUserProfileAction() { IPizzaApiService service = DependencyService.Get <IPizzaApiService>(); SetUserProfileRequest setUserProfileRequest = new(); setUserProfileRequest.Email = Mail; setUserProfileRequest.PhoneNumber = Phone; setUserProfileRequest.LastName = Name; setUserProfileRequest.FirstName = Firstname; Response <UserProfileResponse> response = await service.SetUserProfile(setUserProfileRequest, AccessToken); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert("Error", "Informations not valid", "OK"); } else { await Application.Current.MainPage.DisplayAlert("Great !", "Your profile has been changed", "OK"); await NavigationService.PopAsync(); } }
public static async void Register(INavigation nav, string email, string firstname, string lastname, string phone, string password) { IPizzaApiService service = DependencyService.Get <IPizzaApiService>(); Response <LoginResponse> response; try { response = await service.Register(User.client_id, User.client_secret, email, firstname, lastname, phone, password); } catch (Exception e) { Console.WriteLine(e.Message); throw new Exception(); } if (response.IsSuccess) { Console.WriteLine($"Access Token : {response.Data}"); Console.WriteLine($"Access Token : {response.Data.AccessToken}"); Console.WriteLine($"Access Token : {response.Data.RefreshToken}"); User.Instance.access_token = response.Data.AccessToken; User.Instance.refresh_token = response.Data.RefreshToken; User.Instance.token_type = response.Data.TokenType; User.Instance.expires_in = response.Data.ExpiresIn; User.Instance.is_connected = true; await nav.PushAsync(new HomePage()); } else { Console.WriteLine($"Error {response.ErrorCode} : {response.ErrorMessage}"); } }
public static async void Connection(INavigation nav, string login, string password) { IPizzaApiService service = DependencyService.Get <IPizzaApiService>(); Response <LoginResponse> response; try { response = await service.Connect(login, password, User.client_id, User.client_secret); } catch (Exception e) { Console.WriteLine(e); throw; } Console.WriteLine($"Appel HTTP : {response.IsSuccess} "); if (response.IsSuccess) { Console.WriteLine($"Access Token : {response.Data}"); Console.WriteLine("Connexion Réussi"); User.Instance.access_token = response.Data.AccessToken; User.Instance.refresh_token = response.Data.RefreshToken; User.Instance.token_type = response.Data.TokenType; User.Instance.expires_in = response.Data.ExpiresIn; User.Instance.is_connected = true; await nav.PushAsync(new HomePage()); } else { Console.WriteLine($"Error {response.ErrorCode} : {response.ErrorMessage}"); } }
// Add order on api private async void OrderRequest(long idShop, List <long> ids) { CreateOrderRequest orderRequest = new() { PizzaIds = ids }; IPizzaApiService service = DependencyService.Get <IPizzaApiService>(); Response <OrderItem> response = await service.Order(idShop, orderRequest);; if (response.IsSuccess) { await App.Current.MainPage.DisplayAlert("Commande", "Votre commande a été effectuée !", "Ok !"); EmptyList(); } }
public async void LoginAction() { IPizzaApiService service = DependencyService.Get <IPizzaApiService>(); Response <LoginResponse> response = await service.Login(Mail, Password); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert("Error", "Authentification error", "OK"); } else { CrossSettings.Current.AddOrUpdateValue("AccessToken", JsonConvert.SerializeObject(response.Data.AccessToken)); CrossSettings.Current.AddOrUpdateValue("mail", JsonConvert.SerializeObject(Mail)); CrossSettings.Current.AddOrUpdateValue("password", JsonConvert.SerializeObject(Password)); await NavigationService.PushAsync <LoginPage>(); Mail = ""; Password = ""; } }
public async void SetPasswordAction() { IPizzaApiService service = DependencyService.Get <IPizzaApiService>(); SetPasswordRequest setPasswordRequest = new() { OldPassword = OldPassword, NewPassword = NewPassword }; Response <UserProfileResponse> response = await service.SetPasswordProfile(setPasswordRequest, AccessToken); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert("Error", "Password not valid", "OK"); } else { CrossSettings.Current.AddOrUpdateValue("password", JsonConvert.SerializeObject(NewPassword)); await Application.Current.MainPage.DisplayAlert("Great !", "Password changed successfully", "OK"); await NavigationService.PopAsync(); } } }
void AddPizzaPanier(object sender, System.EventArgs e) { Button btn = (Button)sender; long idPizza = Convert.ToInt64(btn.ClassId.ToString()); Device.BeginInvokeOnMainThread(async() => { IPizzaApiService service = DependencyService.Get <IPizzaApiService>(); Response <List <PizzaItem> > response = await service.ListPizzas(_idShop); Console.WriteLine($"Appel HTTP : {response.IsSuccess}"); if (response.IsSuccess) { Console.WriteLine($"Appel HTTP : {response.Data.Count}"); Pizzas = new ObservableCollection <PizzaItem>(response.Data); } foreach (PizzaItem p in Pizzas) { if (p.Id == idPizza) { if (p.OutOfStock) { await this.DisplayAlert("Pas ok", "La pizza n'est plus en stock", "Ok"); } else { panierpizzId.Add(idPizza); await this.DisplayAlert("Ok", "La pizza a été ajoutée au panier", "Ok"); prix += p.Price; } } } }); }