예제 #1
0
        public ProfileViewModel()
        {
            //Obtencion de datos del perfil
            ApiClientProfile profileInf = LoginViewModel.GetInstance().ClientProfile;

            if (profileInf != null)
            {
                var         profileImageBytes = Convert.FromBase64String(Convert.ToString(profileInf.PP));
                ImageSource profileImage;
                if (profileImageBytes.Length != 0)
                {
                    profileImage = ImageSource.FromStream(() => new MemoryStream(profileImageBytes));
                }
                else
                {
                    profileImage = ImageSource.FromFile("userF.png");
                }


                MyClient = new ClientProfile()
                {
                    ProfileImage    = profileImage,
                    Apellido        = profileInf.Apellido,
                    PrimerNombre    = profileInf.PrimerNombre,
                    SegundoNombre   = profileInf.SegundoNombre,
                    SegundoApellido = profileInf.SegundoApellido,
                    Email           = profileInf.Email,
                    Afiliado        = profileInf.Afiliado
                };

                this.NombreApellido = $"{MyClient.PrimerNombre} {MyClient.Apellido}";

                _instance = this;
            }
            else
            {
                //Datos locales
            }
        }
예제 #2
0
        public async void LoginCommandExecute()
        {
            await Device.InvokeOnMainThreadAsync(() => {
                this.IsBusy    = true;
                this.IsEnabled = false;
            });

            await Task.Delay(10000);

            /*Logueandome y obteniendo un token*/
            if (userLogin.password != null && userLogin.userName != null)
            {
                proc = new RestServiceConsumer();
                var controllerString = $"{Constantes.LOGINAUTH}{Constantes.LOGINAUTHUSERPAR}={userLogin.userName}&{Constantes.LOGINAUTHPASSPAR}={userLogin.password}";
                var response         = await proc.Get <string>(Constantes.BASEURL, Constantes.LOGINPREFIX, controllerString);

                if (!response.IsSuccesFull)
                {
                    //Errores en la respuesta
                    if (response.Result == null)
                    {
                        await Application.Current.MainPage.DisplayAlert("Error!", "Credenciales incorrectas", "OK");

                        return;
                    }
                    //Manejo de otros errores
                    await Application.Current.MainPage.DisplayAlert("Error!", response.Message, "OK");

                    return;
                }

                Settings.SerializedToken = Convert.ToString(response.Result);
                Settings.IsRemembered    = RememberMe;


                var profileControllerString = $"{Constantes.CLIENTPROFILE}{Constantes.LOGINAUTHUSERPAR}={userLogin.userName}&{Constantes.LOGINAUTHPASSPAR}={userLogin.password}";
                var profileResponse         = await proc.Get <ApiClientProfile>(Constantes.BASEURL, Constantes.CLIENTPREFIX, profileControllerString, Settings.SerializedToken);

                if (!profileResponse.IsSuccesFull)
                {
                    await Application.Current.MainPage.DisplayAlert("Error!", response.Message, "OK");

                    return;
                }
                ApiClientProfile profileInfo = (ApiClientProfile)profileResponse.Result;
                this.ClientProfile = profileInfo;
                Settings.FullName  = $"{profileInfo.PrimerNombre} {profileInfo.SegundoNombre} {profileInfo.Apellido} {profileInfo.SegundoApellido}";



                //Navegacion a la pagina Root bloqueando el regreso al Login
                Application.Current.MainPage = new RootHomePage();
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Error!", "Todos los datos son obligatorios", "OK");
            }
            await Device.InvokeOnMainThreadAsync(() => {
                this.IsBusy    = false;
                this.IsEnabled = true;
            });
        }