private void AddCatalogBrands(CatalogDBContext context) { var preconfiguredBrands = useCustomizationData ? GetCatalogBrandsFromFile() : PreconfiguredData.GetPreconfiguredCatalogBrands(); int sequenceId = GetSequenceIdFromSelectedDBSequence(context, DBBrandSequenceName); foreach (var brand in preconfiguredBrands) { brand.Id = sequenceId; context.CatalogBrands.Add(brand); sequenceId++; } context.SaveChanges(); }
static IEnumerable <CatalogBrand> GetCatalogBrandsFromFile() { var contentRootPath = HostingEnvironment.ApplicationPhysicalPath; string csvFileCatalogBrands = Path.Combine(contentRootPath, "Setup", "CatalogBrands.csv"); if (!File.Exists(csvFileCatalogBrands)) { return(PreconfiguredData.GetPreconfiguredCatalogBrands()); } string[] csvheaders; string[] requiredHeaders = { "catalogbrand" }; csvheaders = GetHeaders(csvFileCatalogBrands, requiredHeaders); return(File.ReadAllLines(csvFileCatalogBrands) .Skip(1) // skip header row .Select(x => CreateCatalogBrand(x)) .Where(x => x != null)); }