public ActionResult Index(HttpPostedFileBase uploadFile)
        {
            if (uploadFile.ContentLength > 0)
            {
                var streamReader = new StreamReader(uploadFile.InputStream);

                var gtinList = new List <string>();
                while (!streamReader.EndOfStream)
                {
                    gtinList.Add(streamReader.ReadLine());
                }

                var productsWithInfo    = new List <string>();
                var productsWithAdvices = new List <string>();
                foreach (var gtin in gtinList)
                {
                    var result = _productApplicationService.FindProductByGtin(gtin, true);
                    if (!string.IsNullOrEmpty(result.ProductName))
                    {
                        productsWithInfo.Add(result.ProductName);
                    }
                    if (result.ProductAdvices.Count > 0 ||
                        result.Brand.BrandAdvices.Count > 0 ||
                        (result.Brand.Owner != null && result.Brand.Owner.CompanyAdvices.Count > 0) ||
                        result.Ingredients.Any(x => x.IngredientAdvices.Count > 0))
                    {
                        productsWithAdvices.Add(result.ProductName);
                    }
                }
                ViewData["ProdWithInfo"]    = productsWithInfo;
                ViewData["ProdWithAdvices"] = productsWithAdvices;
            }
            return(View());
        }
Esempio n. 2
0
        public JsonResult GetProductImageLink(string gtin)
        {
            var product = _productApplicationService.FindProductByGtin(gtin, false);

            var result = Json(product.ImageUrlMedium);

            return(result);
        }
        public SearchResultMessageEntity Search(string userSubcriptionToken, string queryString, IShopgunWebOperationContext shopgunWebOperationContext)
        {
            //TODO identify User
            User user = null;

            ////TODO Check for Subscription token, is valid. Maybe it this shall been done the webservice?

            SearchResultMessageEntity result;
            bool productExistsInDatabase = false;

            if (queryString.IsGtin())
            {
                Log.Debug("GTIN search for {0}", queryString);
                var product = _productApplicationService.FindProductByGtin(queryString, true);
                //var product = _productApplicationService.FindProductByGtinInOwnDatabase(queryString, true);

                result = new SearchResultMessageEntity();
                if (!string.IsNullOrEmpty(product.ProductName))
                {
                    result.SearchType = SearchResultMessageEntity.GtinSearch;
                    result.Products   = new List <Product> {
                        product
                    };
                }
                else if (product.Brand != null)
                {
                    if (!string.IsNullOrEmpty(product.Brand.BrandName))
                    {
                        result.SearchType = SearchResultMessageEntity.FreeSearch;
                        result.Brands     = new List <Brand> {
                            product.Brand
                        };
                    }
                    else if (product.Brand.Owner != null)
                    {
                        result.SearchType = SearchResultMessageEntity.FreeSearch;
                        result.Companies  = new List <Company> {
                            product.Brand.Owner
                        };
                    }
                }
                if (product.Id > 0)
                {
                    productExistsInDatabase = true;
                }
            }
            else
            {
                Log.Debug("Freetext search for \"{0}\"", queryString);
                result =
                    new SearchResultMessageEntity
                {
                    SearchType = SearchResultMessageEntity.FreeSearch
                    ,
                    //Brands = _brandApplicationService.FindBrands(queryString, true)
                    //,
                    //Companies = _companyApplicationService.FindCompanies(queryString, true)
                    //,
                    //Concepts = _conceptApplicationService.FindConcepts(queryString, true)
                    //,
                    //Countries = _countryApplicationService.FindCountries(queryString, true)
                    //,
                    //Ingredients = _ingredientApplicationService.FindIngredients(queryString, true, true)
                };
                //Only exact match for now...
                var ingredient = _ingredientApplicationService.FindIngredient(queryString, true, true);
                if (ingredient != null)
                {
                    result.Ingredients = new List <Ingredient> {
                        ingredient
                    };
                }
                var company = _companyApplicationService.FindCompany(queryString, true);
                if (ingredient == null && company != null)
                {
                    result.Companies = new List <Company> {
                        company
                    };
                    result.SearchType = SearchResultMessageEntity.FreeSearch;
                }

                //if (!result.HasResults())
                //{
                //    result.Products = _productDomainService.FindProducts(queryString, true);
                //}
            }
            var resultFound = result.HasResults();

            if (shopgunWebOperationContext != null)
            {
                var userAgent = shopgunWebOperationContext.UserAgent;
                var imei      = shopgunWebOperationContext.IMEI;
                var model     = shopgunWebOperationContext.Model;
                var osVersion = shopgunWebOperationContext.OsVersion;

                _adviceSearchStatisticsDomainService.AddAdviceSearch(user, queryString, userAgent, imei, model, resultFound, osVersion);
            }

            if (result.SearchType != SearchResultMessageEntity.GtinSearch || productExistsInDatabase)
            {
                //_statisticsDomainService.AddStatistics(user, result, userAgent, imei, model, osVersion);
            }

            return(result);
        }