private void LoadSearchResults() { PerformAction(async() => { try { _isSearchInProgress = true; var stockItems = await _stockBussinessLogic.SearchStockItems(SearchText, _searchPageIndex); if (stockItems != null && stockItems.Count > 0) { if (_searchPageIndex == 1) { StockItems.Clear(); } var tempStockItems = new ObservableCollection <StockModel>(); foreach (var stockItem in stockItems) { tempStockItems.Add(stockItem); } StockItems = new ObservableCollection <StockModel>(StockItems.Concat(tempStockItems)); SelectedStockItem = StockItems.FirstOrDefault(); } } finally { _tracker.Stop(); Log.Info(string.Format("Time taken by stock search is {0}ms", _tracker.Elapsed.TotalMilliseconds)); SearchText = string.Empty; } }, SearchTextFieldName); }
/// <summary> /// Loads the view-model. /// </summary> /// <returns>The async.</returns> /// <param name="parameters">Parameters.</param> protected override async Task LoadAsync(IDictionary <string, object> parameters) { try { InProgress = true; // reset the list everytime we load the page StockItems.Clear(); var stockItems = await _stocklistWebServiceController.GetAllStockItems(); // for all contracts build stock item view model and add to the observable collection foreach (var model in stockItems.Select(x => { var model = _stockItemFactory(); model.Apply(x); return(model); })) { StockItems.Add(model); } InProgress = false; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } }
/// <summary> /// Loads all the Stock items /// </summary> private void LoadAllStockItems() { PerformAction(async() => { _isSearchInProgress = false; var stockItems = await _stockBussinessLogic.GetStockItems(_allStockItemsPageIndex); if (stockItems != null && stockItems.Count > 0) { if (_allStockItemsPageIndex == 1) { StockItems.Clear(); } var tempStockItems = new ObservableCollection <StockModel>(); foreach (var stockItem in stockItems) { tempStockItems.Add(stockItem); } StockItems = new ObservableCollection <StockModel>(StockItems.Concat(tempStockItems)); } }, SearchTextFieldName); }