Пример #1
0
        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();
        }
Пример #2
0
        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));
        }