private async void InitModelTree(EkCarTypeEnum?carType, string modelId) { Assure.CheckFlowState(carType != null || modelId != null, $"Either {nameof(carType)} or {nameof(modelId)} should not be null."); // free UI thread await ThreadHelper.RunInBackgroundThreadAsync(() => { // build model tree var carModelTree = EkSettingsHelper.GetCarModelTree(); if (carModelTree == null || carModelTree.Length == 0) { return(Task.CompletedTask); } foreach (var ekCarGroup in carModelTree) { var groupCategory = new Category(ekCarGroup.CarType); _allGroups[groupCategory.Id] = groupCategory; foreach (var manufacturer in ekCarGroup.Manufacturers) { var manufacturerCategory = new Category(ekCarGroup.CarType, manufacturer) { ParentCategoryId = groupCategory.Id, }; _allManufacturers[manufacturerCategory.Id] = manufacturerCategory; foreach (var carModel in manufacturer.CarModels) { var modelCategory = new Category(carModel) { ParentCategoryId = manufacturerCategory.Id, }; _allModels[modelCategory.Id] = modelCategory; } } } Category selectedCategory = null; if (modelId != null) { selectedCategory = _allModels.GetValueOrDefault(modelId); } else if (carType != null) { selectedCategory = _allGroups.GetValueOrDefault(carType.ToString()); } if (selectedCategory == null) { selectedCategory = _allGroups.Values.First(); } SelectCategory(selectedCategory); return(Task.CompletedTask); }); }
public CarModelTreeSearchProvider( EkCarTypeEnum?carType, string modelId, Action onBackToRoot) { _onBackToRoot = onBackToRoot; RetryOnErrorCommand = new RelayCommand( nameof(RetryOnErrorCommand), parameter => { // only modifications request fail is possible UpdateModifications(); }); string manufacturerId = null; if (!String.IsNullOrEmpty(modelId) && modelId != "0") { var model = EkSettingsHelper.GetModelAndNameByModelId(modelId); carType = model.CarType; manufacturerId = model.ManufacturerId.ToString(); } _carType = carType; InitModelTree(carType, manufacturerId, null); }
private async void InitCategories(string initialCategoryId) { List <string> availableCategories = null; /*if (_modelId != 0) * { * try * { * var response = await ServerApiHelper.ProductCategoriesByCarModelModificationAsync( * new EkKioskProductCategoriesByCarModelModificationGetRequest() * { * FullModelName = EkSettingsHelper.GetModelFullNameByModelId(_modelId.ToString()), * }, * CancellationToken.None); * availableCategories = response.CategoriesIds.Select(x => x.ToString()).ToList(); * } * catch(Exception) * { * } * }*/ // free UI thread await ThreadHelper.RunInBackgroundThreadAsync(() => { // build categories var rootCategories = EkSettingsHelper.GetEuropeCategories().Where(x => availableCategories == null || availableCategories.Contains(x.CategoryId)).ToArray(); if (rootCategories == null || rootCategories.Length == 0) { return(Task.CompletedTask); } BuildCategories(null, null, rootCategories, availableCategories);; Category selectedCategory = null; if (initialCategoryId != null) { selectedCategory = _allCategories.GetValueOrDefault(initialCategoryId); // if initial category is leaf then change category if (selectedCategory != null && !selectedCategory.IsGroup) { ChangeCategory(selectedCategory); return(Task.CompletedTask); } } if (selectedCategory == null) { selectedCategory = _allCategories.GetValueOrDefault(rootCategories[0].CategoryId); } SelectCategory(selectedCategory); return(Task.CompletedTask); }); }
private async void InitCategories(string initialCategoryId) { // free UI thread await ThreadHelper.RunInBackgroundThreadAsync(() => { // build categories var rootCategories = EkSettingsHelper.GetEuropeCategories(); if (rootCategories == null || rootCategories.Length == 0) { return(Task.CompletedTask); } BuildCategories(null, rootCategories); Category selectedCategory = null; if (initialCategoryId != null) { selectedCategory = _allCategories.GetValueOrDefault(initialCategoryId); // if initial category is leaf then change category if (selectedCategory != null && !selectedCategory.IsGroup) { ChangeCategory(selectedCategory); return(Task.CompletedTask); } } if (selectedCategory == null) { selectedCategory = _allCategories.GetValueOrDefault(rootCategories[0].CategoryId); } SelectCategory(selectedCategory); return(Task.CompletedTask); }); }