public void DisplayDiscountData() { DiscountDataLoading = true; DiscountListResponse response = new DiscountSQLiteRepository() .GetDiscountsByPage(MainWindow.CurrentCompanyId, DiscountSearchObject, currentPage, itemsPerPage); if (response.Success) { DiscountsFromDB = new ObservableCollection <DiscountViewModel>(response.Discounts ?? new List <DiscountViewModel>()); totalItems = response.TotalItems; } else { DiscountsFromDB = new ObservableCollection <DiscountViewModel>(); 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; DiscountDataLoading = false; }
private void PopulateFromDb(string filterString = "") { Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { DiscountListResponse discountResponse = new DiscountSQLiteRepository().GetDiscountsForPopup(MainWindow.CurrentCompanyId, filterString); if (discountResponse.Success) { if (discountResponse.Discounts != null && discountResponse.Discounts.Count > 0) { DiscountsFromDB = new ObservableCollection <DiscountViewModel>( discountResponse.Discounts?.OrderBy(x => Int32.Parse(x.Code))?.ToList() ?? new List <DiscountViewModel>()); if (DiscountsFromDB.Count == 1) { CurrentDiscount = DiscountsFromDB.FirstOrDefault(); } } else { DiscountsFromDB = new ObservableCollection <DiscountViewModel>(); CurrentDiscount = null; } } }) ); }
private void BtnDelete_Click(object sender, RoutedEventArgs e) { Thread th = new Thread(() => { DiscountDataLoading = true; if (CurrentDiscount == null) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Morate_odabrati_stavku_za_brisanjeUzvičnik")); DiscountDataLoading = false; return; } DiscountResponse response = DiscountService.Delete(CurrentDiscount.Identifier); if (!response.Success) { MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_brisanja_sa_serveraUzvičnik")); DiscountDataLoading = false; return; } response = new DiscountSQLiteRepository().Delete(CurrentDiscount.Identifier); if (!response.Success) { MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_brisanjaUzvičnik")); DiscountDataLoading = false; return; } MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_obrisaniUzvičnik")); DisplayDiscountData(); DiscountDataLoading = false; }); th.IsBackground = true; th.Start(); }