示例#1
0
        private async void Login()
        {
            if (string.IsNullOrEmpty(this.VerificationCode))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "¡Ups!",
                    "Ingresa el código de verificación",
                    "Ok");

                return;
            }

            var connection = this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                await Application.Current.MainPage.DisplayAlert(
                    "¡Ups!",
                    "Debes conectarte a internet",
                    "Ok");

                return;
            }

            if (VerificationCode != Code)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "¡Ups!",
                    "Código de verificación incorrecto",
                    "Ok");

                return;
            }

            var mainViewModel = MainViewModel.GetInstance();

            if (!(IsExistingUser && !string.IsNullOrEmpty(AccountInstance.Email)))
            {
                mainViewModel.AccountVM = new AccountViewModel
                {
                    AccountInstance         = AccountInstance,
                    PersonalAccountInstance = new PersonalAccount {
                        Account = PhoneNumber
                    },
                    EnterpriseAccountInstance = new EnterpriseAccount {
                        Account = PhoneNumber
                    }
                };

                await Application.Current.MainPage.Navigation.PushModalAsync(new AccountTypePage(), false);
            }
            else
            {
                var response = await apiService.Get <PersonalAccount>(Constants.PERSONAL_ACCOUNT, AccountInstance.PhoneNumber);

                //Verifico el tipo de cuenta, si es personal o empresarial
                if (!response.IsSuccess)
                {
                    response = await apiService.Get <EnterpriseAccount>(Constants.ENTERPRISE_ACCOUNT, AccountInstance.PhoneNumber);

                    EnterpriseAccount enterprise = ((EnterpriseAccount)response.Result);
                    Username = enterprise.EnterpriseName;
                    Settings.EnterpriseAccountSettings = JsonConvert.SerializeObject(enterprise);
                }
                else
                {
                    PersonalAccount personal = (PersonalAccount)response.Result;
                    Username = personal.Name;
                    Settings.PersonalAccountSettings = JsonConvert.SerializeObject(personal);
                }

                mainViewModel.MenuVM = new MenuViewModel
                {
                    AccountInstance = AccountInstance,
                    UserName        = Username //Nombre de la cuenta
                };

                Settings.AccountSettings = JsonConvert.SerializeObject(AccountInstance);

                Settings.IsLoggedIn = true;
                await Application.Current.MainPage.Navigation.PushModalAsync(new MenuPage(), false);
            }
        }
        /// <summary>
        /// Sets the account that will be used to authenticate to the API as the enterprise.
        /// Documentation https://developers.google.com/androidenterprise/v1/reference/enterprises/setAccount
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Androidenterprise service.</param>
        /// <param name="enterpriseId">The ID of the enterprise.</param>
        /// <param name="body">A valid Androidenterprise v1 body.</param>
        /// <returns>EnterpriseAccountResponse</returns>
        public static EnterpriseAccount SetAccount(AndroidenterpriseService service, string enterpriseId, EnterpriseAccount body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (enterpriseId == null)
                {
                    throw new ArgumentNullException(enterpriseId);
                }

                // Make the request.
                return(service.Enterprises.SetAccount(body, enterpriseId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Enterprises.SetAccount failed.", ex);
            }
        }