Пример #1
0
        async Task ExecuteLoadManufacturersCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Manufacturers.Clear();
                var items = await restService.GetResponse <List <Manufacturer> >(Constants.urlApi + "manufacturers", true);

                foreach (var item in items)
                {
                    Manufacturers.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
 public void UpdateProductsList(IEnumerable <Product> products)
 {
     Products.Clear();
     Manufacturers.Clear();
     FillProducts(products);
     NotifyPropertyChanged("Products");
 }
 public void UpdateProductsList()
 {
     try
     {
         Products.Clear();
         Manufacturers.Clear();
         VehicleEngine vehicleEngine = UserConfiguration.GetUserConfiguration().SelectedVehicleEngine;
         Category      category      = UserConfiguration.GetUserConfiguration().SelectedCategory;
         if (vehicleEngine != null && category != null)
         {
             try
             {
                 vehiclePart = storeService.VehiclePartService.GetVehiclePart(
                     vehicleEngine, category);
                 FillProducts(storeService.ProductService.GetProductsByVehiclePart(vehiclePart));
                 NotifyPropertyChanged("Products");
             }
             catch (Exception e)
             {
                 WindowProvider.NotifyWindow(e.Message);
             }
         }
         else
         {
             WindowProvider.NotifyWindow("Автомобиль не выбран");
         }
     }
     catch (Exception e)
     {
         WindowProvider.NotifyWindow(e.Message);
     }
 }
Пример #4
0
 private void FillManufacturers()
 {
     Manufacturers.Clear();
     foreach (Manufacturer manufacturer in storeService.ManufacturerService.GetAllManufacturers())
     {
         Manufacturers.Add(manufacturer);
     }
 }
Пример #5
0
 public void Clear()
 {
     Languages.Clear();
     Currencies.Clear();
     StoreMappings.Clear();
     CustomerRoleMappings.Clear();
     Manufacturers.Clear();
     Categories.Clear();
     DeliveryTimes.Clear();
     Translations.Clear();
     CustomProperties.Clear();
 }
Пример #6
0
        public SelectManufacturerPageViewModel(INavigationService navigationService,
                                               IManufacturerService manufacturerService,
                                               IDialogService dialogService
                                               ) : base(navigationService, dialogService)
        {
            Title = "选择供应商";

            _navigationService   = navigationService;
            _dialogService       = dialogService;
            _manufacturerService = manufacturerService;

            //Load
            this.Load = ManufacturersLoader.Load(async() =>
            {
                //重载时排它
                ItemTreshold = 1;
                try
                {
                    //清除列表
                    Manufacturers.Clear();

                    var items = await GetManufacturersPage(0, PageSize);
                    if (items != null)
                    {
                        foreach (var item in items)
                        {
                            if (Manufacturers.Count(s => s.Id == item.Id) == 0)
                            {
                                Manufacturers.Add(item);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }

                this.Manufacturers = new ObservableRangeCollection <ManufacturerModel>(Manufacturers);


                return(Manufacturers.ToList());
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                using (var dig = UserDialogs.Instance.Loading("加载中..."))
                {
                    try
                    {
                        int pageIdex         = Manufacturers.Count / (PageSize == 0 ? 1 : PageSize);
                        var items            = await GetManufacturersPage(pageIdex, PageSize);
                        var previousLastItem = Terminals.Last();
                        if (items != null)
                        {
                            foreach (var item in items)
                            {
                                if (Manufacturers.Count(s => s.Id == item.Id) == 0)
                                {
                                    Manufacturers.Add(item);
                                }
                            }

                            if (items.Count() == 0 || items.Count() == Terminals.Count)
                            {
                                ItemTreshold = -1;
                                return(Manufacturers.ToList());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                        ItemTreshold = -1;
                    }


                    this.Manufacturers = new ObservableRangeCollection <ManufacturerModel>(Manufacturers);
                    return(Manufacturers.ToList());
                }
            }, this.WhenAny(x => x.Terminals, x => x.GetValue().Count > 0));


            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                await _navigationService.GoBackAsync(("Manufacturer", item));
                this.Selecter = null;
            }).DisposeWith(DeactivateWith);

            this.BindBusyCommand(Load);
        }