Ejemplo n.º 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();
        }
        private void AddCatalogBrands(CatalogDBContext context)
        {
            var preconfiguredBrands = _dataSettings.UseCustomizationData
                ? GetCatalogBrandsFromFile()
                : PreconfiguredData.GetPreconfiguredCatalogBrands();

            foreach (var brand in preconfiguredBrands)
            {
                if (context.CatalogBrands.FirstOrDefault(x => x.Id.Equals(brand.Id)) == null)
                {
                    brand.Id = brand.Id;
                    context.CatalogBrands.Add(brand);
                }
            }

            context.SaveChanges();
        }
Ejemplo n.º 3
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));
        }