예제 #1
0
        public async Task <List <ProductWithQuantity> > SortProducts(string sortOptions)
        {
            switch (sortOptions)
            {
            case string option when(option.Equals(SortOptions.Low.ToString(), StringComparison.OrdinalIgnoreCase)):
                return((await _apiCaller.GetProducts()).OrderBy(x => x.Price).ToList());

            case string option when(option.Equals(SortOptions.High.ToString(), StringComparison.OrdinalIgnoreCase)):
                return((await _apiCaller.GetProducts()).OrderByDescending(x => x.Price).ToList());

            case string option when(option.Equals(SortOptions.Ascending.ToString(), StringComparison.OrdinalIgnoreCase)):
                return((await _apiCaller.GetProducts()).OrderBy(x => x.Name).ToList());

            case string option when(option.Equals(SortOptions.Descending.ToString(), StringComparison.OrdinalIgnoreCase)):
                return((await _apiCaller.GetProducts()).OrderByDescending(x => x.Name).ToList());

            case string option when(option.Equals(SortOptions.Recommended.ToString(), StringComparison.OrdinalIgnoreCase)):
                return(await SortByPopularity());

            default:
                break;
            }

            return(null);
        }