private async Task LoadTable()
        {
            Ad  ad     = new Ad();
            var adList = await(ad.GetAllAdsForFavorites());

            var favoredAds = adList.Where(row => row.IsLiked).ToList();

            for (int i = 0; i < favoredAds.Count; i++)
            {
                string adID    = favoredAds[i].ID;
                var    adLocal = await AdLocal.GetAdLocalByAdID(adID);

                if (adLocal == null || string.IsNullOrEmpty(adLocal.AdID))
                {
                    adLocal          = new AdLocal();
                    adLocal.AdID     = adID;
                    adLocal.Sequence = favoredAds.Count;
                }

                favoredAds[i].ClientFavoritesSortOrder = adLocal.Sequence;
                favoredAds[i].Notes = adLocal.Notes;
            }

            favoredAds = favoredAds.OrderBy(row => row.ClientFavoritesSortOrder).ToList();

            InvokeOnMainThread(() =>
            {
                LoadingOverlayProperty.Hide();
                FavoritesAdList           = favoredAds;
                FavoritesTableView.Source = new FavoritesTableSource(this);

                FavoritesTableView.ReloadData();
            });
        }
        public override void MoveRow(UITableView tableView, NSIndexPath sourceIndexPath, NSIndexPath destinationIndexPath)
        {
            var item     = Owner.FavoritesAdList[sourceIndexPath.Row];
            var deleteAt = sourceIndexPath.Row;
            var insertAt = destinationIndexPath.Row;

            // are we inserting
            if (destinationIndexPath.Row < sourceIndexPath.Row)
            {
                // add one to where we delete, because we're increasing the index by inserting
                deleteAt += 1;
            }
            else
            {
                // add one to where we insert, because we haven't deleted the original yet
                insertAt += 1;
            }
            Owner.FavoritesAdList.Insert(insertAt, item);
            Owner.FavoritesAdList.RemoveAt(deleteAt);

            //Set sequencee
            Task.Run(async() =>
            {
                for (int i = 0; i < Owner.FavoritesAdList.Count; i++)
                {
                    Owner.FavoritesAdList[i].ClientFavoritesSortOrder = i;

                    //if ad local doesn't exist, create it and set values
                    var adLocal = await AdLocal.GetAdLocalByAdID(Owner.FavoritesAdList[i].ID);
                    if (adLocal == null || string.IsNullOrEmpty(adLocal.AdID))
                    {
                        adLocal      = new AdLocal();
                        adLocal.AdID = Owner.FavoritesAdList[i].ID;
                    }

                    adLocal.Sequence = i;
                    adLocal.Notes    = Owner.FavoritesAdList[i].Notes;
                    AdLocal.SaveAdLocalByAdID(adLocal, Owner.FavoritesAdList[i].ID);
                }
            });
        }
        public override void ViewDidDisappear(bool animated)
        {
            //unregister from events
            EditTableButton.TouchUpInside -= EditTableButton_TouchUpInside;
            RefreshButton.TouchUpInside   -= RefreshButton_TouchUpInside;

            return;

            var localModifiedAdList = FavoritesAdList.Where(row => row.IsModified).ToList();

            //Save modifications made to ads while browsing a magazine
            if (localModifiedAdList != null && localModifiedAdList.Count > 0)
            {
                var classifications = localModifiedAdList.Select(row => row.Classification).Distinct();
                //var classifications = Settings.GetFavoredClassifications();
                if (classifications.Count() > 0)
                {
                    Task.Run(async() =>
                    {
                        foreach (var classification in classifications)
                        {
                            var modifiedAdsByClassification = localModifiedAdList.Where(row => row.Classification == classification);

                            var allAdsByClassification = (await Ad.GetAdsByClassificationAsync(classification)).ToList();
                            //remove favorite ads from all ads list

                            //int sequence = 0;
                            foreach (var modifiedAd in modifiedAdsByClassification)
                            {
                                var adWithSameAdID = allAdsByClassification.FirstOrDefault(row => row.ID == modifiedAd.ID);
                                if (adWithSameAdID != null)
                                {
                                    allAdsByClassification.Remove(adWithSameAdID);
                                }

                                //if ad local doesn't exist, create it and set values
                                var adLocal = await AdLocal.GetAdLocalByAdID(modifiedAd.ID);
                                if (adLocal == null || string.IsNullOrEmpty(adLocal.AdID))
                                {
                                    adLocal      = new AdLocal();
                                    adLocal.AdID = modifiedAd.ID;
                                }
                                adLocal.Sequence = modifiedAd.ClientFavoritesSortOrder;
                                adLocal.Notes    = modifiedAd.Notes;
                                AdLocal.SaveAdLocalByAdID(adLocal, modifiedAd.ID);

                                modifiedAd.IsModified = false;
                            }


                            //add favorite ads back into all ads list
                            allAdsByClassification.AddRange(modifiedAdsByClassification);

                            Ad.SaveAdsByClassification(allAdsByClassification, classification);
                        }
                    });
                }
            }


            FavoritesAdList = null;


            base.ViewDidDisappear(animated);
        }