Exemplo n.º 1
0
 public string ProcessBrands(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
 {
     var brandDatas = dataReader.GetBrands();
     foreach (BrandData brandData in brandDatas)
     {
         string name = brandData.Name.Trim();
         Brand brand =
             _session.QueryOver<Brand>()
                 .Where(b => b.Name.IsInsensitiveLike(name, MatchMode.Exact))
                 .List().FirstOrDefault();
         if (brand == null)
         {
             brand = _getNewBrandPage.Get(name);
             _session.Transact(session => session.Save(brand));
         }
         nopImportContext.AddEntry(brandData.Id, brand);
     }
     return string.Format("{0} brands processed", brandDatas.Count);
 }
Exemplo n.º 2
0
        public string ProcessBrands(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            var brandDatas = dataReader.GetBrands();

            foreach (BrandData brandData in brandDatas)
            {
                string name  = brandData.Name.Trim();
                Brand  brand =
                    _session.QueryOver <Brand>()
                    .Where(b => b.Name.IsInsensitiveLike(name, MatchMode.Exact))
                    .List().FirstOrDefault();
                if (brand == null)
                {
                    brand = _getNewBrandPage.Get(name);
                    _session.Transact(session => session.Save(brand));
                }
                nopImportContext.AddEntry(brandData.Id, brand);
            }
            return(string.Format("{0} brands processed", brandDatas.Count));
        }
Exemplo n.º 3
0
        public string ProcessBrands(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            HashSet <BrandData> brandDatas = dataReader.GetBrands();
            var brands = _session.QueryOver <Brand>().List().ToDictionary(x => x.Name);
            var site   = _session.Get <Site>(_site.Id);

            foreach (BrandData brandData in brandDatas)
            {
                string name = brandData.Name.Trim();
                Brand  brand;
                if (!brands.ContainsKey(name))
                {
                    brand = _getNewBrandPage.Get(name);
                    brand.AssignBaseProperties(site);
                    _session.Transact(session => session.Insert(brand));
                }
                else
                {
                    brand = brands[name];
                }
                nopImportContext.AddEntry(brandData.Id, brand);
            }
            return(string.Format("{0} brands processed", brandDatas.Count));
        }