Пример #1
0
        private async Task <List <ProductModel> > GetRecommendedProductList(List <ProductModel> productList)
        {
            List <ProductModel> sortedProductList = new List <ProductModel>();

            if ((productList != null) && (productList.Count > 0))
            {
                var shopperHistories = await _externalService.GetShopperHistory();

                List <string> sortedProductListFromHistory = GetSortedProductListFromHistory(shopperHistories);
                foreach (string ph in sortedProductListFromHistory) //add products from history
                {
                    List <ProductModel> foundProducts = productList.FindAll(p => (p.Name == ph));
                    if (foundProducts != null)
                    {
                        sortedProductList.AddRange(foundProducts);
                    }
                }
                foreach (ProductModel p in productList) //add products not found from history
                {
                    if (!sortedProductList.Exists(sp => (sp.Name == p.Name)))
                    {
                        sortedProductList.Add(p);
                    }
                }
            }
            return(sortedProductList);
        }