Example #1
0
        private void GetHostDetail()
        {
            if (IsBusy || !ConnectivityHelper.IsNetworkAvailable())
            {
                return;
            }

            IsBusy = true;
            Task.Run(async() =>
            {
                return(await databaseService.GetHostDetails(scannedToken));
            }).ContinueWith(task => Device.BeginInvokeOnMainThread(() =>
            {
                IsBusy = false;
                if (task.Status == TaskStatus.RanToCompletion)
                {
                    if (task.Result != null)
                    {
                        if (task.Result.Success)
                        {
                            OnLogInSuccess(task.Result.Host);
                        }
                        else if (!string.IsNullOrWhiteSpace(task.Result.Message))
                        {
                            CoreMethods.DisplayAlert("", task.Result.Message, TranslateExtension.GetValue("ok"));
                        }
                        else
                        {
                            CoreMethods.DisplayAlert("Request Fail", "Property not found", TranslateExtension.GetValue("ok"));
                        }
                    }
                    else
                    {
                        CoreMethods.DisplayAlert("", TranslateExtension.GetValue("dialog_message_server_error"), TranslateExtension.GetValue("ok"));
                    }
                }
                else if (task.IsFaulted)
                {
                    CoreMethods.DisplayAlert(TranslateExtension.GetValue("error"), task.Exception?.GetBaseException().Message, TranslateExtension.GetValue("ok"));
                }
            }));
        }
        private void NewTermsConditions(object sender)
        {
            if (IsBusy || !ConnectivityHelper.IsNetworkAvailable())
            {
                return;
            }

            Task.Run(async() =>
            {
                return(await termsConditionsService.NewTermsConditions(Host));
            }).ContinueWith(task => Device.BeginInvokeOnMainThread(() =>
            {
                if (task.Status == TaskStatus.RanToCompletion)
                {
                    if (task.Result != null)
                    {
                        if (task.Result.Success)
                        {
                            CoreMethods.DisplayAlert("Update Successfully", task.Result.Message, TranslateExtension.GetValue("ok"));
                            CoreMethods.PopViewModel();
                        }
                        else
                        {
                            CoreMethods.DisplayAlert("Update Unsuccessfully", task.Result.Message, TranslateExtension.GetValue("ok"));
                        }
                    }
                    else
                    {
                        CoreMethods.DisplayAlert("Update Unsuccessfully", TranslateExtension.GetValue("dialog_message_server_error"), TranslateExtension.GetValue("ok"));
                    }
                }
                else if (task.IsFaulted)
                {
                    CoreMethods.DisplayAlert(TranslateExtension.GetValue("error"), task.Exception?.GetBaseException().Message, TranslateExtension.GetValue("ok"));
                }
            }));
        }
        public Task <bool> SyncFromServer(int method, Action onSuccess, Action <string> onError = null, bool showOverlay = false)
        {
            if (!ConnectivityHelper.IsNetworkAvailable(method == 2))
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    onError?.Invoke(TranslateExtension.GetValue("alert_no_internt_message"));
                });
                return(Task.FromResult(false));
            }

            if (showOverlay)
            {
                DependencyService.Get <IPopupService>().ShowContent(new LoadingScreen1()
                {
                    Message = TranslateExtension.GetValue("content_message_synchronizing")
                });
            }

            Task.Run(async() =>
            {
                return(await SyncFromServer(method));
            }).ContinueWith(task => Device.BeginInvokeOnMainThread(() =>
            {
                if (showOverlay)
                {
                    DependencyService.Get <IPopupService>().HideContent();
                }

                if (task.Status == TaskStatus.RanToCompletion)
                {
                    if (task.Result)
                    {
                        if (showOverlay)
                        {
                            UserDialogs.Instance.Toast(new ToastConfig(TranslateExtension.GetValue("alert_message_sync_completed"))
                            {
                            });
                        }
                        onSuccess?.Invoke();
                    }
                    else
                    {
                        if (showOverlay)
                        {
                            UserDialogs.Instance.Toast(new ToastConfig(TranslateExtension.GetValue("alert_message_sync_failed"))
                            {
                            });
                        }
                        onError?.Invoke(TranslateExtension.GetValue("alert_message_sync_failed"));
                    }
                }
                else if (task.IsFaulted && task.Exception?.GetBaseException().Message is string message)
                {
                    if (showOverlay)
                    {
                        UserDialogs.Instance.Toast(new ToastConfig(message)
                        {
                        });
                    }
                    onError?.Invoke(message);
                }
            }));

            return(Task.FromResult(true));
        }