protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility
       = AppViewBackButtonVisibility.Collapsed;
     listaPaci.SelectedIndex = -1;
     usu = e.Parameter as Usuario;
     tu.Text = usu.Nombre + " " +usu.Apellido;
     
 }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     usu = e.Parameter as Usuario;
     nombre.Text = usu.Nombre;
     apellido.Text = usu.Apellido;
     correo.Text = usu.Correo;
     telefono.Text = "" + usu.Telefono;
     cedula.Text = usu.Cedula;
     username.Text = usu.Username;
     password.Password = usu.Password;
     tu.Text = usu.Nombre + " " + usu.Apellido;
 }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     usus = new Collection<Usuario>();
     usus = e.Parameter as Collection<Usuario>;
     usu = usus.ElementAt<Usuario>(1);
     medico = usus.ElementAt<Usuario>(0);
     llenarDatos();
     Nombre.Text = usu.Nombre + " " + usu.Apellido;
     Correo.Text = usu.Correo;
     Cedula.Text = ""+usu.Cedula;
     Telefono.Text = ""+usu.Telefono;              
 }
 public async void register(Usuario usu)
 {
     ParseObject appointment = new ParseObject("User");
     appointment["username"] = usu.Username;
     appointment["password"] = usu.Password;
     appointment["Nombre"] = usu.Nombre;
     appointment["Apellido"] = usu.Apellido;
     appointment["Cedula"] = usu.Cedula;
     appointment["telefono"] = usu.Telefono;
     appointment["email"] = usu.Correo;
     appointment["perfil"] = usu.Perfil;
      
     await appointment.SaveAsync();
 }
        private async void listaNoPaci_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            Usuario lbi1 = new Usuario();
            try { 
            lbi1 = ((sender as ListBox).SelectedItem as Usuario);
            ParseObject appointment = new ParseObject("MedPac");
            appointment["Medico"] = usu.Id;
            appointment["Paciente"] = lbi1.Id;
            await appointment.SaveAsync();
            data.Add(lbi1);
            data1.Remove(lbi1);
            }
            catch (Exception ex)
            {

            }

            //((ObservableCollection<Usuario>)listaNoPaci.ItemsSource).Remove(lbi1);
            //tb.Text = "Cantidad: " + i;
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     usu = e.Parameter as Usuario;
     tu.Text = usu.Nombre + " " + usu.Apellido;
     
 }
        private async void login(object sender, RoutedEventArgs e)
        {
            Esperar.Visibility = Visibility.Visible;
            try { 
            var query = from UsuarioSelected in ParseObject.GetQuery("User")
                        where UsuarioSelected.Get<string>("username") == user.Text
                        where UsuarioSelected.Get<string>("password") == pass.Password
                        select UsuarioSelected;
            ParseObject obj = await query.FirstAsync();

            log = new Usuario();
            log.Id = obj.ObjectId;
            log.Correo = obj.Get<string>("email");
            log.Nombre = obj.Get<string>("Nombre");
            log.Apellido = obj.Get<string>("Apellido");
            log.Cedula = obj.Get<string>("Cedula");
            log.Password = obj.Get<string>("password");
            log.Perfil = obj.Get<string>("perfil");
            log.Username = obj.Get<string>("username");
            log.Telefono = obj.Get<uint>("telefono");
                Esperar.Visibility = Visibility.Collapsed;

            if (log.Perfil == "medico")
            {
                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.Navigate(typeof(Medico), log);
            }
            else if (log.Perfil == "paciente")
            {
                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.Navigate(typeof(Paciente), log);
            }
        }catch(Exception ex){
                Esperar.Visibility = Visibility.Collapsed;
                var dialog = new Windows.UI.Popups.MessageDialog("Revisa tus datos");
                dialog.Commands.Add(new Windows.UI.Popups.UICommand("OK") {  });
                var result = await dialog.ShowAsync();
        }
            /*Frame rootFrame = Window.Current.Content as Frame;
            rootFrame.Navigate(typeof(Medico));*/

        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     usu = e.Parameter as Usuario;
 }
        public async void llenar()
        {
                data = new ObservableCollection<Usuario>();
                data1 = new ObservableCollection<Usuario>();
            try { 
            var query = from UsuarioSelected in ParseObject.GetQuery("User")
                        where UsuarioSelected.Get<string>("perfil") == "paciente"
                        select UsuarioSelected;
            var final = await query.FindAsync();

            var query1 = from PacMed in ParseObject.GetQuery("MedPac")
                         where PacMed.Get<string>("Medico") == usu.Id
                         select PacMed;
            var final1 = await query1.FindAsync();

            Usuario log;
            if (final1.Count() == 0)
            {
                foreach (var obj in final)
                {
                    log = new Usuario();
                    log.Id = obj.ObjectId;
                    log.Correo = obj.Get<string>("Nombre");
                    log.Nombre = obj.Get<string>("Nombre");
                    log.Apellido = obj.Get<string>("Apellido");
                    log.Cedula = obj.Get<string>("Cedula");
                    log.Password = obj.Get<string>("password");
                    log.Perfil = obj.Get<string>("perfil");
                    log.Username = obj.Get<string>("username");
                    data1.Add(log);
                }
            }
            else
            {
                foreach (var obj in final)
                {
                    log = new Usuario();
                    
                    log.Id = obj.ObjectId;
                    log.Correo = obj.Get<string>("Nombre");
                    log.Nombre = obj.Get<string>("Nombre");
                    log.Apellido = obj.Get<string>("Apellido");
                    log.Cedula = obj.Get<string>("Cedula");
                    log.Password = obj.Get<string>("password");
                    log.Telefono = obj.Get<uint>("telefono");
                    log.Perfil = obj.Get<string>("perfil");
                    log.Username = obj.Get<string>("username");
                    data1.Add(log);
                    foreach (var obj1 in final1)
                    {
                        
                        if (obj1.Get<string>("Paciente") == obj.ObjectId)
                        {
                            
                            data1.Remove(log);
                            log.MedPac = obj1.ObjectId; 
                            data.Add(log);
                        }
                       
                    }
                }

            }
            }
            catch (Exception e)
            {
                var panel = new StackPanel();

                panel.Children.Add(new TextBlock
                {
                    Text = "No se ha podido carga la informaciĆ³n de paciente, inicia sesion nuevamente",
                    TextWrapping = TextWrapping.Wrap,
                });

                var dialog = new ContentDialog()
                {
                    Title = "ERROR",
                    MaxWidth = this.MaxWidth
                };

                dialog.Content = panel;
                dialog.PrimaryButtonText = "OK";
                dialog.IsPrimaryButtonEnabled = true;
                dialog.PrimaryButtonClick += delegate {
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(MainPage));
                };
                dialog.ShowAsync();
            }

        }