public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationItem.SetLeftBarButtonItem(
                new UIBarButtonItem(UIImage.FromBundle("menu.png"), UIBarButtonItemStyle.Plain, (s, e) => NavigationController.PopViewController(true)),
                true);

            locations = new AvailableLocations();

            state = locations.States.ElementAt(0);
            currentSelected = locations.PotentialLocations.Where(loc => loc.State == state).ElementAt(0);

            stateTableSource = new StateTableSource(locations);
            cityTableSource = new CityTableSource(locations, locations.States.ElementAt(0));
            StateTableView.Source = stateTableSource;
            CityTableView.Source = cityTableSource;

            StateTableView.SelectRow(NSIndexPath.FromRowSection(0, 0), false, UITableViewScrollPosition.None);

            stateTableSource.ValueChanged += StateTable_Changed;
            cityTableSource.ValueChange += CityTable_Changed;

            RecentCitiesButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                var storyboard = UIStoryboard.FromName("Main", null);
                var recentCitiesViewController = (RecentCitiesTableViewController)storyboard.InstantiateViewController("RecentCitiesTableViewController");
                recentCitiesViewController.FromMenu = false;
                this.ShowViewController(recentCitiesViewController, this);
            };
        }
        public override void RowSelected(UITableView tableView, Foundation.NSIndexPath indexPath)
        {
            AvailableLocations allLocations = new AvailableLocations();
            var categoryVC = new CategoryPickerViewController();
            categoryVC.SelectedCity = allLocations.PotentialLocations.Find(x => x.SiteName == recentCities[indexPath.Row].City);

            this.owner.ShowViewController(categoryVC, this);
        }
 public StateTableSource(AvailableLocations locations)
 {
     this.locations = locations;
 }
 public CityTableSource(AvailableLocations locations, string state)
 {
     citiesInState = locations.PotentialLocations.Where(l => l.State.Equals(state)).OrderBy(l => l.SiteName).ToList();
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            locations = new AvailableLocations();
            state = locations.States.ElementAt((int)StatePickerView.SelectedRowInComponent(0));
            currentSelected = locations.PotentialLocations.Where(loc => loc.State == state).ElementAt(0);

            cityModel = new LocationPickerModel(locations, state);
            CityPickerView.Model = cityModel;

            stateModel = new StatePickerModel(locations);
            StatePickerView.Model = stateModel;

            cityModel.ValueChange += cityPickerChanged;

            CurrentStateLabel.AllTouchEvents += (sender, e) => {
                ShowStatePickerOnly();
            };

            CurrentCityLabel.AllTouchEvents += (sender, e) => {
                ShowCityPickerOnly();
            };

            CurrentStateLabel.ShouldReturn += delegate {
                return false;
            };

            ProceedButton.TouchUpInside += (object sender, EventArgs e) =>
                {
                    var storyboard = UIStoryboard.FromName("Main", null);
                    var searchViewController = (SearchViewController)storyboard.InstantiateViewController("SearchViewController");

                    Console.WriteLine(currentSelected.SiteName);
                    searchViewController.Url = currentSelected.Url;
                    searchViewController.City = currentSelected.SiteName;

                    System.Threading.Tasks.Task.Run(async () => {
                        await AppDelegate.databaseConnection.AddNewRecentCityAsync(currentSelected.SiteName, currentSelected.Url);

                        if (AppDelegate.databaseConnection.GetAllRecentCitiesAsync().Result.Count > 5)
                        {
                            await AppDelegate.databaseConnection.DeleteOldestCityAsync();
                        }
                    });

            //                    this.ShowViewController(searchViewController, this);
                };

            RecentCitiesButton.TouchUpInside += (object sender, EventArgs e) => {
                var storyboard = UIStoryboard.FromName("Main", null);
                var recentCitiesViewController = (RecentCitiesTableViewController)storyboard.InstantiateViewController("RecentCitiesTableViewController");
            //                this.ShowViewController(recentCitiesViewController, this);
            };

            stateModel.ValueChanged += (object sender, EventArgs e) =>
                {
                    state = stateModel.SelectedItem;
                    CityPickerView.Select(0,0,false);

                    currentSelected = locations.PotentialLocations.Where(loc => loc.State == state).ElementAt(0);
                    cityModel = new LocationPickerModel(locations, stateModel.SelectedItem);
                    CityPickerView.Model = cityModel;

                    cityModel.ValueChange += cityPickerChanged;
                    CurrentStateLabel.Text = state;
            //                    ShowCityPickerOnly();
                };
        }
 public StatePickerModel(AvailableLocations locations)
 {
     this.locations = locations;
 }
 public LocationPickerModel(AvailableLocations locations, string state)
 {
     this.locations = locations;
     this.state = state;
 }