Exemplo n.º 1
0
        private void PopulateFromDb(string filterString = "")
        {
            Application.Current.Dispatcher.BeginInvoke(
                System.Windows.Threading.DispatcherPriority.Normal,
                new Action(() =>
            {
                CountryListResponse CountryResponse = new CountrySQLiteRepository().GetCountriesForPopup(MainWindow.CurrentCompanyId, filterString);
                if (CountryResponse.Success)
                {
                    if (CountryResponse.Countries != null && CountryResponse.Countries.Count > 0)
                    {
                        CountriesFromDB = new ObservableCollection <CountryViewModel>(
                            CountryResponse.Countries.ToList() ?? new List <CountryViewModel>());

                        if (CountriesFromDB.Count == 1)
                        {
                            CurrentCountry = CountriesFromDB.FirstOrDefault();
                        }
                    }
                    else
                    {
                        CountriesFromDB = new ObservableCollection <CountryViewModel>();

                        CurrentCountry = null;
                    }
                }
            })
                );
        }
        public void DisplayData()
        {
            CountryDataLoading = true;

            CountryListResponse response = new CountrySQLiteRepository()
                                           .GetCountriesByPage(MainWindow.CurrentCompanyId, CountrySearchObject, currentPage, itemsPerPage);

            if (response.Success)
            {
                CountriesFromDB = new ObservableCollection <CountryViewModel>(response.Countries ?? new List <CountryViewModel>());
                totalItems      = response.TotalItems;
            }
            else
            {
                CountriesFromDB         = new ObservableCollection <CountryViewModel>();
                totalItems              = 0;
                MainWindow.ErrorMessage = response.Message;
            }

            int itemFrom = totalItems != 0 ? (currentPage - 1) * itemsPerPage + 1 : 0;
            int itemTo   = currentPage * itemsPerPage < totalItems ? currentPage * itemsPerPage : totalItems;

            PaginationDisplay = itemFrom + " - " + itemTo + " od " + totalItems;

            CountryDataLoading = false;
        }