Exemple #1
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            userTable = await CloudService.GetTableAsync <User>();

            User currentUser = await userTable.ReadItemAsync(Settings.UserId);

            await UpdateUserLocation(currentUser);

            try
            {
                List <SharingSpace> sharingspaces = await _apiServices.GetNearbyEvents(Settings.AccessToken, "500");

                if (sharingspaces == null)
                {
                    await Application.Current.MainPage.DisplayAlert("No nearby events", "No nearby events.", "OK");

                    Navigation.InsertPageBefore(new HomePage(), this);
                    await Navigation.PopAsync();
                }
                Navigation.InsertPageBefore(new EventJoinPage(sharingspaces), this);
                await Navigation.PopAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error: " + ex.Message);
                await Application.Current.MainPage.DisplayAlert("Getting events failed", ex.Message, "OK");

                // do nothing
            }
        }
        async Task <bool> IsUserRegisteredInTheCloud(ILoginProvider loginProvider)
        {
            ICloudTable <UserDetails> Table = GetTable <UserDetails>();
            string  tableId = loginProvider.RetrieveTableIdFromSecureStore();
            Account account = loginProvider.RetreiveAccountFromSecureStore();

            if (tableId == null)
            {
                ICollection <UserDetails> tempUserDetailsList = await Table.ReadAllItemsAsync();

                UserDetails userDetails = tempUserDetailsList.FirstOrDefault(x => x.userId == client.CurrentUser.UserId);
                account.Properties.Add("table_id", userDetails.Id);
                loginProvider.SaveAccountInSecureStore(account);
                App.UserDetails = userDetails;
            }
            else
            {
                UserDetails tempUserDetails = await Table.ReadItemAsync(tableId);

                App.UserDetails = tempUserDetails;
            }

            if (App.UserDetails != null)
            {
                return(true);
            }
            return(false);
        }