private void SetBrand(ProductImportDataTransferObject dataTransferObject, Product product) { //Brand if (!String.IsNullOrWhiteSpace(dataTransferObject.Brand)) { string dtoBrand = dataTransferObject.Brand.Trim(); Brand brand = _session.QueryOver <Brand>() .Where(b => b.Name.IsInsensitiveLike(dtoBrand, MatchMode.Exact)) .Take(1) .SingleOrDefault(); if (brand == null) { brand = _getNewBrandPage.Get(dtoBrand); _session.Transact(session => session.Save(brand)); } product.BrandPage = brand; } }
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)); }
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)); }