Ejemplo n.º 1
0
        public ClothesViewModelItem(IClothesDetailDomain clothesDetail, IClothesTypeDomain clothesType,
                                    IClothesRestService clothesRestService,
                                    IClothesDetailNavigationService clothesDetailNavigationService)
        {
            ClothesDetail = clothesDetail;
            _clothesType  = clothesType;
            _clothesDetailNavigationService = clothesDetailNavigationService;
            _image = Observable.Return(ImageSource.FromFile("empty_image.png")).
                     ToProperty(this, nameof(Image));
            ImageCommand = ReactiveCommand.CreateFromTask(() => GetImageSource(clothesRestService, ClothesDetail.Id));
            _image       = ImageCommand.ToProperty(this, nameof(Image), scheduler: RxApp.MainThreadScheduler);
            this.WhenAnyValue(x => x.Image).
            Where(x => x != null).
            Subscribe(x => ImageLoad = true);

            ClothesDetailCommand = ReactiveCommand.CreateFromTask(ToClothesDetail);
        }
Ejemplo n.º 2
0
        public ClothesViewModel(IClothesRestService clothesRestService, IClothesNavigationService clothesNavigationService,
                                IChoiceNavigationService choiceNavigationService,
                                IClothesDetailNavigationService clothesDetailNavigationService)
            : base(clothesNavigationService)
        {
            _clothes = this.WhenAnyValue(x => x.NavigationParameters).
                       Where(clothesParameters => clothesParameters != null).
                       SelectMany(parameters => Observable.FromAsync(() => GetClothes(parameters, clothesRestService, clothesDetailNavigationService))).
                       ToProperty(this, nameof(Clothes), scheduler: RxApp.MainThreadScheduler);

            ClothesFilterCommand = ReactiveCommand.Create <Unit, IReadOnlyList <ClothesViewModelItem> >(
                _ => FilterAndSortingViewModelFactory.GetClothesFiltered(Clothes, FilterViewModel.ClothesFilters,
                                                                         SortingViewModel.ClothesSortingType));
            _sortingViewModel = Observable.Return(new SortingViewModel(ClothesFilterCommand)).
                                ToProperty(this, nameof(SortingViewModel));

            _filterViewModel = this.WhenAnyValue(x => x.Clothes, x => x.NavigationParameters, (clothes, parameters) => (clothes, parameters)).
                               Where(clothesNavigation => clothesNavigation.clothes != null && clothesNavigation.parameters != null).
                               Select(clothesNavigation => new FilterViewModel(clothesNavigation.parameters !, clothesNavigation.clothes,
                                                                               ClothesFilterCommand)).
                               ToProperty(this, nameof(FilterViewModel));

            _clothesFiltered = this.WhenAnyValue(x => x.FilterViewModel).
                               Where(filterViewModel => filterViewModel != null).
                               SelectMany(filterViewModel => ClothesFilterCommand).
                               ToProperty(this, nameof(ClothesFiltered));

            _clothesViewModelColumnItems = this.WhenAnyValue(x => x.ClothesFiltered).
                                           Where(clothes => clothes != null).
                                           Select(GetClothesItems).
                                           ToProperty(this, nameof(ClothesViewModelColumnItems));

            ImagesCommand = ReactiveCommand.CreateFromObservable <int, ImageSource>(
                itemIndex => ClothesViewModelColumnItems[itemIndex].ClothesViewModelItemLeft !.
                ImageCommand.Execute(Unit.Default));

            ChoiceNavigateCommand = ReactiveCommand.CreateFromTask(_ => choiceNavigationService.NavigateTo(new ChoiceNavigationParameters()));

            this.WhenAnyValue(x => x.Clothes, x => x.FilterViewModel, (clothes, filterViewModel) => (clothes, filterViewModel)).
            Where(clothes => clothes.clothes != null && clothes.filterViewModel != null).
            Select(_ => Unit.Default).
            InvokeCommand(ClothesFilterCommand);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Получить модели одежды
 /// </summary>
 private static async Task <IReadOnlyCollection <ClothesViewModelItem> > GetClothes(ClothesNavigationParameters?clothesParameters,
                                                                                    IClothesRestService clothesRestService,
                                                                                    IClothesDetailNavigationService clothesDetailNavigationService) =>
 await clothesParameters.ToResultValueNullCheck(new ErrorResult(ErrorResultType.ValueNotFound, nameof(ClothesNavigationParameters))).
 ResultValueBindOkToCollectionAsync(parameters =>
                                    clothesRestService.GetClothesDetails(parameters.GenderType, parameters.ClothesTypeDomain.Name).
                                    ResultCollectionOkTaskAsync(clothes =>
                                                                clothes.Select(clotheItem => new ClothesViewModelItem(clotheItem, parameters.ClothesTypeDomain,
                                                                                                                      clothesRestService, clothesDetailNavigationService)))).
 WhereContinueTaskAsync(result => result.OkStatus,
                        result => result.Value,
                        result => new List <ClothesViewModelItem>());