示例#1
0
        public async Task <IEnumerable <Product> > SortProducts(ProductSortOption sortOption)
        {
            var products = await _resourceHttpClientService.GetProducts();

            switch (sortOption)
            {
            case ProductSortOption.Low:
                return(SortProductsByLowPrice(products.ToList()));

            case ProductSortOption.High:
                return(SortProductsByHighPrice(products.ToList()));

            case ProductSortOption.Ascending:
                return(SortProductsByAscendingName(products.ToList()));

            case ProductSortOption.Descending:
                return(SortProductsByDescendingName(products.ToList()));

            case ProductSortOption.Recommended:
                return(await SortProductsByRecommended(products.ToList()));

            default:
                return(products.ToList());
            }
        }
        public ISortStrategy GetSortStrategy(ProductSortOption sortOption)
        {
            switch (sortOption)
            {
            case ProductSortOption.Low:
                return(_provider.GetRequiredService <PriceLowSortStrategy>());

            case ProductSortOption.High:
                return(_provider.GetRequiredService <PriceHighSortStrategy>());

            case ProductSortOption.Ascending:
                return(_provider.GetRequiredService <NameAscendingSortStrategy>());

            case ProductSortOption.Descending:
                return(_provider.GetRequiredService <NameDescendingSortStrategy>());

            case ProductSortOption.Recommended:
                return(_provider.GetRequiredService <RecommendedSortStrategy>());

            default:
                return(_provider.GetRequiredService <NoSortStrategy>());
            }
        }
 public GetSortedProductsQuery(ProductSortOption productSortOption)
 {
     SortOption = productSortOption;
 }