public ClothesDetailViewModel(IClothesRestService clothesRestService, IClothesDetailNavigationService clothesDetailNavigationService) : base(clothesDetailNavigationService) { var clothesParameters = this.WhenAnyValue(x => x.NavigationParameters). WhereNotNull(). Select(GetClothesParameters); _clothesDetailImageViewModelItems = clothesParameters. SelectMany(parameters => Observable.FromAsync(() => GetClothesImages(clothesRestService, parameters.ClothesDetail.Id))). ToProperty(this, nameof(ClothesDetailImageViewModelItems), scheduler: RxApp.MainThreadScheduler); _name = clothesParameters. Select(parameters => parameters.ClothesDetail.Name). ToProperty(this, nameof(Name)); _description = clothesParameters. Select(parameters => parameters.ClothesDetail.Description). ToProperty(this, nameof(Description)); _price = clothesParameters. Select(parameters => parameters.ClothesDetail.Price). ToProperty(this, nameof(Price)); _sizes = clothesParameters. Select(parameters => (IReadOnlyCollection <ISizeGroupDefaultDomain>)parameters.ClothesDetail.SizeGroups. Select(sizeGroup => new SizeGroupDefaultDomain(sizeGroup, parameters.DefaultSizeType)). ToList()). ToProperty(this, nameof(Sizes)); _colors = clothesParameters. Select(parameters => parameters.ClothesDetail.Colors). ToProperty(this, nameof(Colors)); }
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); }
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); }
/// <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>());
/// <summary> /// Преобразовать изображение в поток /// </summary> private static async Task <ImageSource> GetImageSource(IClothesRestService clothesRestService, int clothesId) => await clothesRestService.GetImage(clothesId). WhereContinueTaskAsync(result => result.OkStatus, result => result.Value, _ => new byte[0]). MapTaskAsync(ImageConverter.ToImageSource);
/// <summary> /// Получить модели изображений /// </summary> private static async Task <IReadOnlyCollection <ClothesDetailImageViewModelItem> > GetClothesImages(IClothesRestService clothesRestService, int clothesId) => await clothesRestService.GetImage(clothesId). WhereContinueTaskAsync(result => result.OkStatus, result => result.Value, _ => new byte[0]). MapTaskAsync(clothesDetailImage => new List <ClothesDetailImageViewModelItem> { new ClothesDetailImageViewModelItem(clothesDetailImage), // new ClothesDetailImageViewModelItem(clothesDetailImage) });