public void AddOpvCertificationMarkMapping(OpvCertificationMarkMapping opvCertificationMarkMapping)
 {
     using (var opvCertificationMarkMappingRepository = _repositoryFactory.Build <IRepository <OpvCertificationMarkMapping>, OpvCertificationMarkMapping>())
     {
         opvCertificationMarkMappingRepository.Add(opvCertificationMarkMapping);
         opvCertificationMarkMappingRepository.Persist();
     }
 }
        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);
        }
Exemple #3
0
        private IList <CertificationMark> MapCertificationMarks(IEnumerable <MarkInfoGWO> opvMarkings)
        {
            using (var opvCertificationMarkMappingsRepository = RepositoryFactory.Build <IRepository <OpvCertificationMarkMapping>, OpvCertificationMarkMapping>())
            {
                var opvCertificationMarkIds = opvMarkings.Select(x => x.MarkId);
                var opvMapppings            = from mapping in opvCertificationMarkMappingsRepository.Find(x => x.ProviderCertificationId != null)
                                              where opvCertificationMarkIds.Contains(mapping.ProviderCertificationId.Value)
                                              select mapping;
                var nonMappedMarkings = from marking in opvMarkings
                                        where
                                        !opvMapppings.Select(x => x.ProviderCertificationId).Contains(marking.MarkId)
                                        select marking;
                var result = opvMapppings.Select(x => x.CertificationMark).ToList();

                foreach (var nonMappedMarking in nonMappedMarkings)
                {
                    result.Add(new CertificationMark
                    {
                        CertificationName = nonMappedMarking.MarkName
                    });
                }

                return(result);
            }
        }
Exemple #4
0
 private IList <CertificationMark> MapMarkingNames(IEnumerable <string> markingNames)
 {
     using (
         var certificationMarkRepository =
             RepositoryFactory.Build <IRepository <CertificationMark>, CertificationMark>())
     {
         IList <CertificationMark> certificationMarks = new List <CertificationMark>(markingNames.Count());
         foreach (var markingName in markingNames)
         {
             var name = markingName;
             CertificationMark certificationMark;
             try
             {
                 certificationMark =
                     certificationMarkRepository.FindOne(m => m.CertificationName == name);
             }
             catch (Exception)
             {
                 Log.Debug("CertificationMark not found when mapping: {0}", name);
                 certificationMark = new CertificationMark {
                     CertificationName = name
                 };
             }
             certificationMarks.Add(certificationMark);
         }
         return(certificationMarks);
     }
 }
Exemple #5
0
 protected override void Before_each_spec()
 {
     using (var adviceRepository = RepositoryFactory.Build <IRepository <AdviceBase>, AdviceBase>())
     {
         var advices = adviceRepository.Find(x => x != null);
         adviceRepository.Delete(advices);
         adviceRepository.Persist();
     }
 }
Exemple #6
0
        /// <summary>
        /// Creates a new Ingredient and returns it. If an Ingredient or an AlternativeIngredientName with the same name already exist, null is returned.
        /// </summary>
        /// <param name="ingredientName"></param>
        /// <returns></returns>
        public Ingredient CreateIngredient(string ingredientName)
        {
            var alternativeNameRepostory =
                _repositoryFactory.Build <IRepository <AlternativeIngredientName>, AlternativeIngredientName>();

            if (string.IsNullOrEmpty(ingredientName) ||
                _ingredientRepository.Find(i => i.IngredientName == ingredientName).Any() ||
                alternativeNameRepostory.Find(ain => ain.AlternativeName == ingredientName).Any())
            {
                return(null);
            }
            var ingredient = new Ingredient {
                IngredientName = ingredientName
            };

            _ingredientRepository.Add(ingredient);
            _ingredientRepository.Persist();
            return(ingredient);
        }
        protected override void Before_all_specs()
        {
            SetupDatabase(ShopGunSpecBase.Database.ShopGun, typeof (Base).Assembly);

            RepositoryFactory = CreateStub<RepositoryFactory<IAdviceRepository, AdviceBase>>();

            _adviceApplicationService = new AdviceApplicationService(null, null);

            var mentorRepository = RepositoryFactory.Build<IRepository<Mentor>, Mentor>();

            _mentor = new Mentor
                          {
                              MentorName = "Consumentor"
                          };
            mentorRepository.Add(_mentor);
            mentorRepository.Persist();


            var semaphoreRepository = RepositoryFactory.Build<IRepository<Semaphore>, Semaphore>();

            _redSemaphore = new Semaphore
                                {
                                    ColorName = "Red",
                                    Value = -1
                                };
            semaphoreRepository.Add(_redSemaphore);
            _greenSemaphore = new Semaphore
                                  {
                                      ColorName = "Green",
                                      Value = 1
                                  };
            semaphoreRepository.Add(_greenSemaphore);
            semaphoreRepository.Persist();


            var productRepository = RepositoryFactory.Build<IRepository<Product>, Product>();

            _product = ProductBuilder.BuildProduct();
            productRepository.Add(_product);
            productRepository.Persist();

        }
Exemple #8
0
        internal Company MapCompany(string companyName)
        {
            using (var companyRepository = RepositoryFactory.Build <IRepository <Company>, Company>())
            {
                companyRepository.ToggleDeferredLoading(false);
                Company company;
                try
                {
                    company = companyRepository.FindOne(c => c.CompanyName == companyName);
                }
                catch (ArgumentException)
                {
                    company = new Company {
                        CompanyName = companyName, LastUpdated = DateTime.Now
                    };
                }

                return(company);
            }
        }
        public bool DeleteCompany(int companyToDeleteId, int?substitutingCompanyId)
        {
            if (substitutingCompanyId == null)
            {
                return(DeleteCompany(companyToDeleteId));
            }
            var companyToDelete     = _companyRepository.FindOne(x => x.Id == companyToDeleteId);
            var substitutingCompany = _companyRepository.FindOne(x => x.Id == substitutingCompanyId);

            using (var brandRepository = _repositoryFactory.Build <IRepository <Brand>, Brand>())
            {
                var brands = from brand in brandRepository.Find(x => x.CompanyId == companyToDelete.Id)
                             select brand;
                foreach (var brand in brands)
                {
                    var tempBrand = _companyRepository.FindDomainObject(brand);
                    tempBrand.Owner = substitutingCompany;
                }
            }

            foreach (var companyAdvice in companyToDelete.CompanyAdvices)
            {
                substitutingCompany.AddAdvice(companyAdvice);
            }
            foreach (var companyStatistic in companyToDelete.CompanyStatistics)
            {
                substitutingCompany.CompanyStatistics.Add(companyStatistic);
            }
            var childCompanies = GetChildCompanies(companyToDelete);

            foreach (var childCompany in childCompanies)
            {
                childCompany.Owner = substitutingCompany;
            }

            _companyRepository.Delete(companyToDelete);
            _companyRepository.Persist();
            Log.Debug("Company '{0}' with Id '{1}' deleted. Substitute company: '{2}' - {3}", companyToDelete.CompanyName,
                      companyToDelete.Id, substitutingCompany.Id, companyToDelete.CompanyName);
            return(true);
        }
Exemple #10
0
        protected override void Before_all_specs()
        {
            SetupDatabase(ShopGunSpecBase.Database.ShopGun, typeof(Base).Assembly);

            RepositoryFactory = CreateStub <RepositoryFactory <IAdviceRepository, AdviceBase> >();

            _adviceApplicationService = new AdviceApplicationService(null, null);

            var mentorRepository = RepositoryFactory.Build <IRepository <Mentor>, Mentor>();

            _mentor = new Mentor
            {
                MentorName = "Consumentor"
            };
            mentorRepository.Add(_mentor);
            mentorRepository.Persist();


            var semaphoreRepository = RepositoryFactory.Build <IRepository <Semaphore>, Semaphore>();

            _redSemaphore = new Semaphore
            {
                ColorName = "Red",
                Value     = -1
            };
            semaphoreRepository.Add(_redSemaphore);
            _greenSemaphore = new Semaphore
            {
                ColorName = "Green",
                Value     = 1
            };
            semaphoreRepository.Add(_greenSemaphore);
            semaphoreRepository.Persist();


            var productRepository = RepositoryFactory.Build <IRepository <Product>, Product>();

            _product = ProductBuilder.BuildProduct();
            productRepository.Add(_product);
            productRepository.Persist();
        }
Exemple #11
0
        private void SetOwner(Brand brand, int?companyId)
        {
            if (companyId == null)
            {
                brand.Owner = null;
                return;
            }
            var companyRepository = _repositoryFactory.Build <IRepository <Company>, Company>();

            var owner = companyRepository.FindOne(x => x.Id == companyId);

            brand.Owner = _brandRepository.FindDomainObject(owner);
        }
Exemple #12
0
 public IngredientAdvice AddIngredientAdvice(Mentor mentor, IngredientAdvice advice)
 {
     if (advice.IngredientsId == null)
     {
         throw new ArgumentException("IngredientsId cannot be null when adding IngredientAdvice");
     }
     using (var ingredientRepository = _repositoryFactory.Build <IRepository <Ingredient>, Ingredient>())
     {
         var ingredient = ingredientRepository.FindOne(x => x.Id == advice.IngredientsId);
         return(AddAdvice(mentor, advice, ingredient));
     }
 }
 public BrandApplicationService(RepositoryFactory repositoryFactory)
 {
     _repositoryFactory = repositoryFactory;
     _brandRepository = _repositoryFactory.Build<IBrandRepository, Brand>();
 }
 public IngredientApplicationService(RepositoryFactory repositoryFactory)
 {
     _repositoryFactory = repositoryFactory;
     _ingredientRepository = _repositoryFactory.Build<IIngredientRepository, Ingredient>();
 }
Exemple #15
0
 /// <summary>
 /// Initializer
 /// </summary>
 public CategoriesController()
 {
     repositoryFactory = new ModelsFactory();
     container         = repositoryFactory.Build();
 }
        public override Product Map(ProductGWO source)
        {
            var company = MapCompany(source.Supplier);
            var brand   = MapBrand(source.Trademark);

            if (brand.Owner == null)
            {
                brand.Owner = company;
            }
            var ingredients   = MapTableOfContentsToIngredients(source.Content);
            var originCountry = MapOriginCountry(source.Origin);

            IList <AllergyInformation> allergyInformation = new List <AllergyInformation>();

            foreach (var allergyInfoGwo in source.Allergies)
            {
                var ingredient = MapIngredient(allergyInfoGwo.SubstanceName);
                allergyInformation.Add(new AllergyInformation
                {
                    Allergene = ingredient,
                    Remark    = allergyInfoGwo.Remark
                });
            }

            var certificationMarks = new List <CertificationMark>();

            using (
                var certificationMarkRepository =
                    RepositoryFactory.Build <IRepository <CertificationMark>, CertificationMark>())
            {
                foreach (var markInfoGwo in source.Markings)
                {
                    var markInfoGwoCopy = markInfoGwo;
                    CertificationMark certificationMark;
                    try
                    {
                        certificationMark =
                            certificationMarkRepository.FindOne(m => m.CertificationName == markInfoGwoCopy.MarkName);
                    }
                    catch (Exception)
                    {
                        certificationMark = new CertificationMark {
                            CertificationName = markInfoGwo.MarkName
                        };
                    }
                    certificationMarks.Add(certificationMark);
                }
            }

            return(new Product
            {
                AllergyInformation = allergyInformation,
                Brand = brand,
                Description = "",
                GlobalTradeItemNumber = source.EAN,
                //Ingredients = ingredients,
                //CertificationMarks = certificationMarks,
                OriginCountry = originCountry,
                ProductName = source.Name,
                //Quantity =
                QuantityUnit = source.WeightVolume,
                TableOfContent = source.Content,
                LastUpdated = DateTime.Now,
                Durability = source.Durability,
                ImageUrlLarge = source.ImageURL_Jpg300px,
                ImageUrlMedium = source.ImageURL_Jpg150px,
                ImageUrlSmall = source.ImageURL_Jpg66px,
                Nutrition = source.Nutrition,
                SupplierArticleNumber = source.SuppArtNo
            });
        }
Exemple #17
0
 public BrandApplicationService(RepositoryFactory repositoryFactory)
 {
     _repositoryFactory = repositoryFactory;
     _brandRepository   = _repositoryFactory.Build <IBrandRepository, Brand>();
 }
Exemple #18
0
        private void UpdateDomain(router router, string gtin, itemDataLineType gepirProduct)
        {
            if (string.IsNullOrEmpty(gepirProduct.brandName))
            {
                return;
            }
            using (var brandRepository = _repositoryFactory.Build <IBrandRepository, Brand>())
            {
                Brand brand          = null;
                var   matchingBrands = brandRepository.Find(x => x.BrandName == gepirProduct.brandName);

                // If a brand with the given name doesn't exist yet, we create it.
                if (!matchingBrands.Any())
                {
                    brand = new Brand {
                        BrandName = gepirProduct.brandName, LastUpdated = DateTime.Now
                    };
                    brandRepository.Add(brand);
                }
                // Else if there exists exactly one brand with the given name we use that brand
                else if (matchingBrands.Count() == 1)
                {
                    brand = matchingBrands.First();

                    // If the brand we retrieved doesn't have an owner we can add it as well
                    if (brand.Owner == null)
                    {
                        var manufacturerGln = gepirProduct.manufacturerGln ?? gepirProduct.informationProviderGln;
                        var getPartyByGln   = new GetPartyByGLN {
                            requestedGln = new[] { manufacturerGln }, versionSpecified = false
                        };
                        var partyByGln = router.GetPartyByGLN(getPartyByGln);
                        if (partyByGln != null && partyByGln.partyDataLine != null && partyByGln.partyDataLine.Length > 0)
                        {
                            using (var companyRepository = _repositoryFactory.Build <IRepository <Company>, Company>())
                            {
                                var     manufacturer      = partyByGln.partyDataLine[0];
                                Company company           = null;
                                var     matchingCompanies =
                                    companyRepository.Find(x => x.CompanyName == manufacturer.partyName);
                                if (!matchingCompanies.Any())
                                {
                                    company = _gepirCompanyMapper.Map(manufacturer);
                                    companyRepository.Add(company);
                                    companyRepository.Persist();
                                }
                                else if (matchingCompanies.Count() == 1)
                                {
                                    company = matchingCompanies.First();
                                }

                                // If we added or found the correct company
                                if (company != null)
                                {
                                    //Todo: This should actually be done within the repository
                                    var brandOwner = brandRepository.FindDomainObject(company);
                                    brand.Owner = brandOwner;
                                }

                                brandRepository.Persist();

                                using (var productRepository = _repositoryFactory.Build <IProductRepository, Product>())
                                {
                                    // If product doesn't exist in database yet - add it.
                                    if (!productRepository.Find(x => x.GlobalTradeItemNumber == gtin).Any())
                                    {
                                        gepirProduct.gtin = gtin;
                                        var newProduct = _gepirProductMapper.Map(gepirProduct);
                                        productRepository.Add(newProduct);
                                        productRepository.Persist();
                                    }
                                }
                            }
                        }
                    }
                }

                if (brand != null && brand.Owner == null)
                {
                }
            }
        }
Exemple #19
0
 public IngredientApplicationService(RepositoryFactory repositoryFactory)
 {
     _repositoryFactory    = repositoryFactory;
     _ingredientRepository = _repositoryFactory.Build <IIngredientRepository, Ingredient>();
 }
 public CompanyApplicationService(RepositoryFactory repositoryFactory)
 {
     _repositoryFactory = repositoryFactory;
     _companyRepository = _repositoryFactory.Build <IRepository <Company>, Company>();
 }
Exemple #21
0
 /// <summary>
 /// Initializer
 /// </summary>
 public UsersController()
 {
     repositoryFactory = new ModelsFactory();
     container         = repositoryFactory.Build();
 }
 public CompanyApplicationService(RepositoryFactory repositoryFactory)
 {
     _repositoryFactory = repositoryFactory;
     _companyRepository = _repositoryFactory.Build<IRepository<Company>, Company>();
 }
Exemple #23
0
 private IProductRepository GetProductRepository()
 {
     return(_repositoryFactory.Build <IProductRepository, Product>());
 }
 /// <summary>
 /// Initializer
 /// </summary>
 public AdvertisementsController(IImageHandler imageHandler)
 {
     repositoryFactory = new ModelsFactory();
     container         = repositoryFactory.Build();
     _imageHandler     = imageHandler;
 }