Ejemplo n.º 1
0
        /// <summary>
        /// This method checks if the keyword is included in the product
        /// If it is, it is included in the returnd list.
        /// </summary>
        /// <param name="products"></param>
        /// <param name="keywords"></param>
        /// <returns></returns>
        private List <Product> keyWorkFilters(List <Product> products, AppliedFiltersList keywords)
        {
            bool filterFound = true;

            List <Product> returnProducts = new List <Product>();

            foreach (Product p in products)
            {
                filterFound = true;
                foreach (AppliedFilters a in keywords.AppliedFilters)
                {
                    if (!p._productName.ToLower().Contains(a.name) && !p._amount.ToLower().Contains(a.name))
                    {
                        // If the keyword is in either the _amout (used for descirption sometimes in the api)
                        // or the _productname it is added.
                        //returnProducts.Add(p);
                        filterFound = false;
                        break;
                    }
                }
                if (filterFound)
                {
                    returnProducts.Add(p);
                }
            }
            return(returnProducts);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This method checks whether or nort Bilka is enabled.
 /// If it is, the Salling api will be called
 /// </summary>
 /// <param name="stores">The list of enabled stores names</param>
 /// <returns></returns>
 private bool IsBilkTrue(AppliedFiltersList stores)
 {
     foreach (var item in stores.AppliedFilters)
     {
         if (item.name == "Bilka")
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Find the products who fit the filters applied, and searchterm
        /// </summary>
        /// <param name="searchterm"></param>
        /// <returns></returns>
        public async Task <List <Product> > UseTogglefilters(string searchterm)
        {
            List <Product> FilteredProductList = new List <Product>();
            bool           flag = false;
            int            i    = 0;


            List <Product> searchedProducts = await dc.Product.GetRange(searchterm, _productsToMatch, _productsToMatch *_loadCount);

            AppliedFiltersList keyWordFilters = new AppliedFiltersList(ToggleWordFilters, wordArray);

            // Returns a list of string of the keywords enabled
            AppliedFiltersList storeNameFilters = new AppliedFiltersList(ToggleStoreFILters, storeArray);

            //This loop always runs two times. One time is to get all products fitting form the database.
            // The next run is if no results are found, and the Salling api is called to ses if any
            // matches can be found there.
            do
            {
                if (flag && IsBilkTrue(storeNameFilters))
                {
                    // Is called if there are returned no products fitting to the filters
                    // and if bilka is turned on.
                    // It calls the Salling API (Bilka2go) and retuns a list of products.
                    FilteredProductList = SearchForProducts(searchterm);
                    flag = false;
                }

                // Returns all products who are in stores enabled
                FilteredProductList = StoreFilter(searchedProducts, storeNameFilters);

                if (keyWordFilters.AppliedFilters.Count != 0)
                {
                    // If there are any keyword filters enabled, this returns the products
                    FilteredProductList = keyWorkFilters(FilteredProductList, keyWordFilters);
                }

                if (CheckList(FilteredProductList, out flag))
                {
                    // If the FilteredProductList contains products, it breaks.
                    // Otherwise the loop runs again to search in the Salling api.
                    break;
                }
            } while (i++ <= 2);
            return(FilteredProductList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method looks at where all the products coms from.
        /// If they are from a store in the stores input, they
        /// are returned.
        /// </summary>
        /// <param name="products"></param>
        /// <param name="stores">The list of storesnames which are enabled in the filters</param>
        /// <returns></returns>
        private List <Product> StoreFilter(List <Product> products, AppliedFiltersList stores)
        {
            List <Product> returnProducts = new List <Product>();

            foreach (Product p in products)
            {
                foreach (AppliedFilters a in stores.AppliedFilters)
                {
                    if (p._storeName.Equals(a.name))
                    {
                        // If the product checked is from one of the stores enabled,
                        // it is added to the returned list
                        returnProducts.Add(p);
                        break;
                    }
                }
            }
            return(returnProducts);
        }