public void SetLocations(IEnumerable <Location> locations)
 {
     this.locations = locations;
     paises         = locations.Select(x => x.Pais).Distinct().ToList();
     paises.Sort();
     paises.Insert(0, other);
     PaisListTextField.SetListableObjects(paises);
     if (selected == null)
     {
         PaisListTextField.ForceInvokeEvent();
     }
     else
     {
         int indexPais = paises.IndexOf(selected.Pais);
         PaisListTextField.SetSelectionIndex(indexPais);
         ciudades = locations.Where(x => x.Pais.Equals(selected.Pais)).Select(x => x.Ciudad).Distinct().ToList();
         ciudades.Sort();
         ciudades.Insert(0, other);
         CiudadListTextField.SetListableObjects(ciudades);
         var index = ciudades.IndexOf(selected.Ciudad);
         CiudadListTextField.SetSelectionIndex(index);
         var filtered = locations.Where(x => x.Pais.Equals(selected.Pais) && x.Ciudad.Equals(selected.Ciudad)).OrderBy(x => x.Name).ToList();
         filtered.Insert(0, new Location()
         {
             Name = other, Pais = paises[indexPais], Ciudad = ciudades[index], IdLocation = -1
         });
         var s = filtered.Where(x => x.IdLocation == selected.IdLocation).First();
         index = filtered.IndexOf(s);
         CenterListTextField.SetListableObjects(filtered);
         CenterListTextField.SetSelectionIndex(index);
     }
 }
        void ReleaseDesignerOutlets()
        {
            if (BackButton != null)
            {
                BackButton.Dispose();
                BackButton = null;
            }

            if (CenterListTextField != null)
            {
                CenterListTextField.Dispose();
                CenterListTextField = null;
            }

            if (CiudadListTextField != null)
            {
                CiudadListTextField.Dispose();
                CiudadListTextField = null;
            }

            if (Label1 != null)
            {
                Label1.Dispose();
                Label1 = null;
            }

            if (Label2 != null)
            {
                Label2.Dispose();
                Label2 = null;
            }

            if (Label3 != null)
            {
                Label3.Dispose();
                Label3 = null;
            }

            if (mandatoryLabel != null)
            {
                mandatoryLabel.Dispose();
                mandatoryLabel = null;
            }

            if (ModifyButton != null)
            {
                ModifyButton.Dispose();
                ModifyButton = null;
            }

            if (PaisListTextField != null)
            {
                PaisListTextField.Dispose();
                PaisListTextField = null;
            }

            if (TitleViewLabel != null)
            {
                TitleViewLabel.Dispose();
                TitleViewLabel = null;
            }
        }
        protected override void AssingViews()
        {
            BackButton.TouchUpInside   += (o, e) => presenter.BackClicked();
            ModifyButton.TouchUpInside += ModifyButton_TouchUpInside;

            PaisListTextField.ItemChanged += (o, pais) =>
            {
                if (pais.Equals(other))
                {
                    CiudadListTextField.SetListableObjects(new List <string>()
                    {
                        other
                    });
                    CenterListTextField.SetListableObjects(new List <Location>()
                    {
                        new Location()
                        {
                            Name = other, Pais = other, Ciudad = other, IdLocation = -1
                        }
                    });
                }
                else
                {
                    var filtered = locations.Where(x => x.Pais.Equals(pais)).OrderBy(x => x.Name).ToList();
                    filtered.Insert(0, new Location()
                    {
                        Name = other, Pais = pais, Ciudad = other, IdLocation = -1
                    });
                    CenterListTextField.SetListableObjects(filtered);
                    ciudades = locations.Where(x => x.Pais.Equals(pais)).Select(x => x.Ciudad).Distinct().ToList();
                    ciudades.Sort();
                    ciudades.Insert(0, other);
                    CiudadListTextField.SetListableObjects(ciudades);
                }
            };
            CiudadListTextField.ItemChanged += (o, ciudad) =>
            {
                if (ciudad.Equals(other))
                {
                    var filtered = locations.Where(x => x.Pais.Equals(PaisListTextField.Text)).OrderBy(x => x.Name).ToList();
                    filtered.Insert(0, new Location()
                    {
                        Name = other, Pais = PaisListTextField.Text, Ciudad = other, IdLocation = -1
                    });
                    CenterListTextField.SetListableObjects(filtered);
                }
                else
                {
                    var filtered = locations.Where(x => x.Pais.Equals(PaisListTextField.Text) && x.Ciudad.Equals(ciudad)).OrderBy(x => x.Name).ToList();
                    filtered.Insert(0, new Location()
                    {
                        Name = other, Pais = PaisListTextField.Text, Ciudad = ciudad, IdLocation = -1
                    });
                    CenterListTextField.SetListableObjects(filtered);
                }
            };
            CenterListTextField.ItemChanged += (o, loc) =>
            {
                var l     = loc as Location;
                int index = ciudades.IndexOf(l.Ciudad);
                CiudadListTextField.SetSelectionIndex(index);
                if (index >= 0 && l.IdLocation == -1)
                {
                    l.Ciudad = ciudades[index];
                }
            };


            styleView();
            applyTraslations();
            other = AppDelegate.LanguageBundle.GetLocalizedString("center_other");
        }
        private void ModifyButton_TouchUpInside(object sender, EventArgs e)
        {
            var loc = CenterListTextField.GetSelection() as Location;

            presenter.ModifyClicked(loc);
        }