Esempio n. 1
0
 public Product FindProductByGtinInOwnDatabase(string gtin, bool onlyPublishedAdvices)
 {
     try
     {
         var result = _productRepository.Find(p => p.GlobalTradeItemNumber == gtin).FirstOrDefault();
         if (result == null)
         {
             Log.Debug("No product in database for GTIN {0}", gtin);
             return(null);
         }
         var ingredients = _ingredientApplicationService.FindIngredientsForTableOfContents(result.TableOfContent);
         foreach (var ingredient in ingredients)
         {
             result.AddIngredient(ingredient);
         }
         if (onlyPublishedAdvices)
         {
             RemoveNonpublishedAdvices(result);
         }
         return(result);
     }
     catch (ArgumentException)
     {
         return(null);
     }
 }
        public ItemInfoMessageEntity SearchItems(string userSubscriptionToken, string queryString, int[] maxHitsPerCategory, IShopgunWebOperationContext shopgunWebOperationContext)
        {
            var result = new ItemInfoMessageEntity();

            var queryStrings = queryString.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            using (var productRepository = _repositoryFactory.Build <IRepository <Product>, Product>())
            {
                result.Products =
                    (from p in
                     productRepository.Find(
                         x => queryStrings.All(q => (x.ProductName + " " + x.Brand.BrandName).ToLower().Contains(q)))
                     orderby p.ProductName
                     select new ProductInfo
                {
                    ProductId = p.Id,
                    ProductName = p.ProductName,
                    BrandName = p.Brand.BrandName,
                    CompanyName = p.Brand.Owner != null ? p.Brand.Owner.CompanyName : ""
                    ,
                    NumberAdvices =
                        p.ProductAdvices.Count(x => x.Published) +
                        _ingredientApplicationService.FindIngredientsForTableOfContents(
                            p.TableOfContent).SelectMany(
                            x => x.IngredientAdvices.Where(a => a.Published)).Count()
                }).Take(maxHitsPerCategory[0]).ToList();
            }

            return(result);
        }
Esempio n. 3
0
 internal IList <Ingredient> MapTableOfContentsToIngredients(string tableOfContents)
 {
     return(IngredientApplicationService.FindIngredientsForTableOfContents(tableOfContents));
 }