Exemplo n.º 1
0
        public async Task <List <ShopperHistory> > GetHistoriesAsync()
        {
            using (HttpClient httpClient = HttpClientBuilder.Build(_appSettings))
            {
                _logger.LogDebug($"Requesting shopper histories at {_appSettings.ResourceBaseUrl}/{Constants.Urls.ShopperHistory}");

                return(await httpClient.GetJsonAsync <List <ShopperHistory> >($"{Constants.Urls.ShopperHistory}?token={_appSettings.Token}"));
            }
        }
Exemplo n.º 2
0
        public async Task <List <Product> > GetSortedProductsAsync(SortOptions sortOptions)
        {
            using (HttpClient httpClient = HttpClientBuilder.Build(_appSettings))
            {
                _logger.LogDebug($"Requesting products at {_appSettings.ResourceBaseUrl}/{Constants.Urls.Products}");

                List <Product> products = await httpClient.GetJsonAsync <List <Product> >($"{Constants.Urls.Products}?token={_appSettings.Token}");

                if (products != null && products.Any())
                {
                    switch (sortOptions)
                    {
                    case SortOptions.High:
                        return(products.OrderByDescending(p => p.Price).ToList());

                    case SortOptions.Low:
                        return(products.OrderBy(p => p.Price).ToList());

                    case SortOptions.Ascending:
                        return(products.OrderBy(p => p.Name).ToList());

                    case SortOptions.Descending:
                        return(products.OrderByDescending(p => p.Name).ToList());

                    case SortOptions.Recommended:
                    default:
                        Dictionary <string, int> popularity = await GetProductPopularityAsync();

                        if (popularity != null)
                        {
                            return(products.OrderByDescending(p => GetPopularity(popularity, p.Name)).ToList());
                        }
                        return(products);
                    }
                }

                return(null);
            }
        }