private void CategoryChanged(int pageId) { SelectedHotCategory = HotCategories.FirstOrDefault(x => x.PageId == pageId); if (SelectedHotCategory?.ProductDetails == null || SelectedHotCategory?.ProductDetails.Count == 0) { LoadHotProducts(pageId); } }
private void UpdateQuantities(ObservableCollection <SaleLineModel> saleLines) { foreach (var x in HotCategories) { foreach (var hx in x.ProductDetails) { hx.Quantity = (int)saleLines.Where(y => y.Code == hx.StockCode). Sum(z => double.Parse(z.Quantity, CultureInfo.InvariantCulture)); } } var selectedHotProduct = SelectedHotCategory?.PageId; if (selectedHotProduct.HasValue && selectedHotProduct.Value != 0) { SelectedHotCategory = HotCategories.FirstOrDefault(x => x.PageId == selectedHotProduct); } }
private async void LoadHotProducts(int pageId) { try { var hotProducts = await _stockBussinessLogic.GetHotProducts(pageId); var productDetails = new ObservableCollection <ProductDataModel>(); foreach (var product in hotProducts) { var productDetail = new ProductDataModel { DefaultQuantity = Convert.ToInt32(product.DefaultQuantity, CultureInfo.InvariantCulture), Description = product.Description, ImageSource = new BitmapImage { UriSource = Helper.IsValidURI(product.Image) ? new Uri(product.Image) : null }, StockCode = product.StockCode }; productDetails.Add(productDetail); } HotCategories.FirstOrDefault(x => x.PageId == pageId).ProductDetails = productDetails; MessengerInstance.Send(new RequestForSyncHotProductsMessage()); } finally { OperationsCompletedInLogin++; if (IsSwitchUserStarted) { OperationsCompletedInSwitchUser++; } } }
/// <summary> /// 初始化 /// </summary> private async void InitCategories() { var tasks = new[] { this._netWorkServices.GetAsync <PlayListCategory[]>("FindMusic", "GetPlayListCategories"), this._netWorkServices.GetAsync <PlayListCategory[]>("FindMusic", "GetHotPlayListCategories") }; await Task.WhenAll(tasks); if (tasks.All(x => x.Result.Successed)) { await Task.WhenAll(AllCategories.AddRangeAsync(tasks[0].Result.Data), HotCategories.AddRangeAsync(tasks[1].Result.Data)); } else { //todo 网络提示信息 } }