private async Task LoadCarritoAsync()
        {
            var idCliente = Preferences.Get(Config.UserId, null, Config.SharedName);

            if (idCliente == null)
            {
                return;
            }

            Dialogs.ShowLoading();

            var response = await Connection.Get($"{Urls.Carrito}/completo/{idCliente}")
                           .ConfigureAwait(false);

            Dialogs.HideLoading();

            if (response.Succeeded)
            {
                var carritos = response.ParseBody <List <CarritoListItem> >();
                CarritoItems.ReplaceRange(carritos);
            }
            else
            {
                await Dialogs.AlertAsync(new AlertConfig
                {
                });

                Device.BeginInvokeOnMainThread(() =>
                {
                    Nav?.PopAsync(true);
                });
            }
        }
        public LoginViewModel(Action completeAction)
        {
            LoginCommand = new Command(async(o) => {
                using (this.Dialogs.Loading("Loading"))
                {
                    await Task.Delay(1000);
                }
                bool accountExist = await AccountExist();
                if (!accountExist)
                {
                    await Dialogs.AlertAsync("The account doesn’t exist");
                    return;
                }

                bool isValidPassword = await IsValidPassword();
                if (!isValidPassword)
                {
                    await Dialogs.AlertAsync("The password is incorrect");
                    return;
                }
                Dialogs.Toast("Login Successful");
                using (this.Dialogs.Loading("Loading"))
                {
                    await Task.Delay(2000);
                }

                completeAction?.Invoke();
            });
            TroubleSigningInCommand = new Command(
                async() =>
            {
                await Browser.OpenAsync("https://id.spectrum.net/recover", BrowserLaunchMode.SystemPreferred);
            }
                );
        }
        private async Task RealizarCompraAsync()
        {
            if (Busy)
            {
                return;
            }

            var idCliente = Preferences.Get(Config.UserId, null, Config.SharedName);

            if (idCliente == null)
            {
                return;
            }

            Dialogs.ShowLoading();

            var response = await Connection.Post($"{Urls.Ordenes}/{idCliente}", "")
                           .ConfigureAwait(false);

            Dialogs.HideLoading();

            if (response.Succeeded)
            {
                var detalle = response.ParseBody <ComprobanteDetalleModel>();

                if (detalle == null)
                {
                    return;
                }

                await Dialogs.AlertAsync(new AlertConfig
                {
                    Title   = "Compra realizada",
                    Message = $"Comprobante sinpe: ",
                    OkText  = "Aceptar"
                });

                await LoadCarritoAsync()
                .ConfigureAwait(false);
            }
            else
            {
                await Dialogs.AlertAsync(new AlertConfig
                {
                    Message = "No se pudo completar la operación, intentalo de nuevo",
                    OkText  = "Aceptar"
                });
            }
        }
        private async void SaveUser()
        {
            var isValidPassword = IsValidPassword();
            var isValidEmail    = IsValidEmail();

            if (isValidPassword && isValidEmail)
            {
                if (this.User == null)
                {
                    var user = new User()
                    {
                        Username = Username,
                        Email    = Email,
                        Password = Password,
                    };
                    await UsersDataStore.AddAsync(user);

                    userSaved?.Invoke(user);

                    await Task.Delay(2000);

                    Dialogs.Toast("User created: " + user.Username);
                }
                else
                {
                    var user = this.User;
                    user.Username = Username;
                    user.Email    = Email;
                    user.Password = Password;
                    await UsersDataStore.UpdateAsync(user);

                    userSaved?.Invoke(user);

                    await Task.Delay(1000);

                    Dialogs.Toast("Saved " + user.Username);
                }
            }
            else
            {
                var n         = Environment.NewLine;
                var allErrors = $@"
{String.Join($".{n}", await GetEmailErrors(Email))}
{String.Join($".{n}", GetPasswordErrors(Password) )}
{String.Join($".{n}", GetConfirmPasswordErrors(Password, ConfirmPassword))}";
                await Dialogs.AlertAsync(allErrors, "Error");
            }
            return;
        }
        async Task ExecuteRefreshCommand(bool forceRefresh)
        {
            if (IsBusy)
            {
                return;
            }

            if (!await CheckConnectivityAsync())
            {
                return;
            }

            IsBusy = true;

            try
            {
                Analytics.TrackEvent("SerchedForNearby");
                var position = await GeolocationService.GetCurrentPositionAsync();

                if (position == null)
                {
                    throw new Exception("Unable to get location.");
                }

                ContactsGrouped.Clear();
                var contacts = await DataService.GetNearbyAsync(position.Longitude, position.Latitude);

                if (contacts.Count() > 0)
                {
                    ContactsGrouped.AddRange(contacts);
                }
                else
                {
                    await Dialogs.AlertAsync(null, AppResources.NoCDAsNearby, AppResources.OK);
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                System.Diagnostics.Debug.WriteLine($"*** ERROR: {ex.Message}");
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 6
0
        private async void Submit(object obj)
        {
            if (string.IsNullOrEmpty(FirstName) || string.IsNullOrEmpty(LastName))
            {
                await Dialogs.AlertAsync("Please enter First Name and Last Name.");

                return;
            }

            Dialogs.ShowLoading("Submitting...");
            if (Attendee == null)
            {
                Attendee = new KinderRegistration();
            }
            Attendee.FirstName            = FirstName;
            Attendee.LastName             = LastName;
            Attendee.CompanySchool        = CompanySchool;
            Attendee.Position             = Position;
            Attendee.EmailAddress         = EmailAddress;
            Attendee.TimeIn               = DateTime.Now;
            Attendee.MobileNumber         = MobileNumber;
            Attendee.WillingToBeContacted = Willing;
            Attendee.YearsOfExperience    = Years;

            if (string.IsNullOrEmpty(Attendee.Id))
            {
                await App.Service.AddItem(Attendee);
            }
            else
            {
                await App.Service.UpdateItem(Attendee);
            }

            Clear(null);

            Dialogs.HideLoading();
            await Dialogs.AlertAsync("Registration Complete!");
        }