/*public void test()
         * {
         *      _events = new List<UsuarioPOJO>();
         *      UsuarioPOJO user = new UsuarioPOJO();
         *      user.apellido_materno = "martinez";
         *      UsuarioPOJO user2 = new UsuarioPOJO();
         *      user2.apellido_materno = "rodríguez";
         *      _events.Add(user);
         *      _events.Add(user2);
         * }*/
        /*
         * async void getCalls()
         * {
         * if (PropertiesManager.IsDateCallTrue())
         * {
         * PropertiesManager.SaveCallDate(dateToSend);
         * }
         * else
         * {
         * dateToSend = PropertiesManager.GetDateCall();
         * }
         * CheckConnection();
         * ShowProgress("Validando");
         * var times = dateToSend.ToString("yyyy-MM-dd HH:MM:ss");
         * _calls = await ClientGuanajoven.getCalls(times);
         * var convocatorias = App.CurrentApp.RealmInstance.All<Convocatoria>().ToList();
         * if (_calls != null && _calls.Count > 0)
         * {
         * foreach (var item in _calls)
         * {
         *      var fecha_cierre = DateTime.Parse(item.fecha_cierre);
         *      if (time <= fecha_cierre)
         *      {
         *              item.estatusText = "Activa";
         *      }
         *      else
         *      {
         *              item.estatusText = "Inactiva";
         *      }
         *
         *      foreach (var document in item.documentos)
         *      {
         *              if (document.formato.nombre == "docx")
         *              {
         *                      document.Icono = "ic_doc-web.png";
         *              }
         *              else if (document.formato.nombre == "xlsx")
         *              {
         *                      document.Icono = "ic_xls-web.png";
         *              }
         *              else if (document.formato.nombre == "pdf")
         *              {
         *                      document.Icono = "ic_pdf-web.png";
         *              }
         *              else
         *              {
         *                      document.Icono = "ic_unknow-web.png";
         *              }
         *      }
         * }
         *
         * App.CurrentApp.RealmInstance.Write(() =>
         *              {
         *                      foreach (var item in _calls)
         *                      {
         *                              App.CurrentApp.RealmInstance.Add(item);
         *                      }
         *              });
         * }
         *
         * if (convocatorias != null)
         * {
         *
         * dateToSend = time;
         * PropertiesManager.SaveCallDate(dateToSend);
         * convocatorias = convocatorias.OrderByDescending(x => x.fecha_inicio).ToList();
         * _itemsList.Clear();
         * convocatorias = App.CurrentApp.RealmInstance.All<Convocatoria>().ToList();
         * foreach (var item in convocatorias)
         * {
         *      _itemsList.Add(item);
         * }
         *
         * Device.BeginInvokeOnMainThread(() =>
         * {
         *      if (ListView.ItemsSource != _itemsList)
         *              ListView.ItemsSource = _itemsList;
         * });
         * }
         * HideProgress();	}
         *
         */


        async void getRegion()
        {
            if (PropertiesManager.IsDateRegionTrue())
            {
                PropertiesManager.SaveRegionDate(dateToSend);
            }
            else
            {
                dateToSend = PropertiesManager.GetDataRegion();
            }
            if (PropertiesManager.IsDateFirstRegionTrue())
            {
                PropertiesManager.SaveFirstRegionDate(1);
            }
            else
            {
                PropertiesManager.SaveFirstRegionDate(PropertiesManager.GetFirstDataRegion() + 1);
            }
            CheckConnection();
            ShowProgress("Validando");
            String times = "";

            if (PropertiesManager.GetFirstDataRegion() > 1)
            {
                times = dateToSend.ToString("yyyy-MM-dd HH:MM:ss");
            }
            else
            {
                times = "0000-00-00 00:00:00";
            }
            _regionSer = await ClientGuanajoven.getRegion(times);

            var regiones = App.CurrentApp.RealmInstance.All <Region>().ToList();

            if (_regionSer != null && _regionSer.Count > 0)
            {
                MergeLists(_regionSer);

                /*	App.CurrentApp.RealmInstance.Write(() =>
                 *                      {
                 *                              if (regiones.Count > 0)
                 *                              {
                 *                                      foreach (var region in regiones)
                 *                                      {
                 *                                              foreach (var _region in _regionSer)
                 *                                              {
                 *                                                      if (region.id_region == _region.id_region)
                 *                                                      {
                 *                                                              App.CurrentApp.RealmInstance.Remove(region);
                 *                                                      }
                 *
                 *                                              }
                 *                                      }
                 *                              }
                 *
                 *                              foreach (var item in _regionSer)
                 *                              {
                 *                                      if (item.deleted_at != null)
                 *                                      {
                 *                                      }
                 *                                      else
                 *                                      {
                 *
                 *                                              App.CurrentApp.RealmInstance.Add(item);
                 *                                      }
                 *                              }
                 *                      });*/
            }

            regiones = App.CurrentApp.RealmInstance.All <Region>().ToList();
            if (regiones != null)
            {
                dateToSend = time;
                PropertiesManager.SaveRegionDate(dateToSend);
                regiones = regiones.OrderByDescending(x => x.created_at).ToList();
                _itemsList.Clear();
                //	eventos = App.CurrentApp.RealmInstance.All<Evento>().ToList();
                foreach (var item in regiones)
                {
                    _itemsList.Add(item);
                }


                Device.BeginInvokeOnMainThread(() =>
                {
                    if (ListView.ItemsSource != _itemsList)
                    {
                        ListView.ItemsSource = _itemsList;
                    }
                });
            }
            HideProgress();
        }