Ejemplo n.º 1
0
        public static async Task LoginFB(UserFB usr)
        {
            Console.WriteLine("entra a registrar");

            await Task.Run(async() =>
            {
                try
                {
                    var responseApi = await FbService.PostLogin(usr.id_fbk);


                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (responseApi != null)
                        {
                            if (responseApi["codigo"].ToString() == "1")
                            {
                                var s          = responseApi["data"].ToString();
                                var userLogged = Newtonsoft.Json.JsonConvert.DeserializeObject <UserFB>(s);

                                if (userLogged != null)
                                {
                                    GeneralSetting.UserSettings = JsonConvert.SerializeObject(userLogged);
                                    App.NavigateToProfile();
                                }                                //usuario nuevo registrar pagina
                                else
                                {
                                    var app      = Current as App;
                                    app.MainPage = new NavigationPage(new RegistroPage(usr))
                                    {
                                        BarBackgroundColor = (Color)App.Current.Resources["AzulColor"]
                                    };
                                }
                            }
                            else
                            {
                                var app      = Current as App;
                                app.MainPage = new NavigationPage(new RegistroPage(usr))
                                {
                                    BarBackgroundColor = (Color)App.Current.Resources["AzulColor"]
                                };
                            }
                        }
                    });
                }
                catch (Exception e)
                {
                    Console.WriteLine("ha ocurrido un error");
                }
            });
        }
Ejemplo n.º 2
0
        public async Task Registrar(UserFB usr)
        {
            Console.WriteLine("entra a registrar");

            await Task.Run(async() =>
            {
                try
                {
                    var responseApi = await FbService.PostUserFB(usr);

                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (responseApi != null)
                        {
                            if (responseApi["codigo"].ToString() == "1")
                            {
                                var s       = responseApi["data"].ToString();
                                var newUser = Newtonsoft.Json.JsonConvert.DeserializeObject <UserFB>(s);

                                if (newUser != null)
                                {
                                    //await DisplayAlert("Usuario", "Usuario creado con exito", "Aceptar");
                                    GeneralSetting.UserSettings = JsonConvert.SerializeObject(newUser);
                                    App.NavigateToProfile();
                                    Loading(false);
                                }
                            }
                            else
                            {
                                await DisplayAlert("Usuario", responseApi["mensaje"].ToString(), "Aceptar");
                            }
                        }
                        else
                        {
                            Loading(false);
                            await DisplayAlert("Usuario", "Ha ocurrido un error", "Aceptar");
                        }
                    });
                }
                catch (Exception e)
                {
                    Loading(false);
                    await DisplayAlert("Usuario", "Ha ocurrido un error " + e.Message, "Aceptar");
                }
            });
        }