private void AddCatalogItems(CatalogDBContext context) { var preconfiguredItems = useCustomizationData ? GetCatalogItemsFromFile(context) : PreconfiguredData.GetPreconfiguredCatalogItems(); foreach (var item in preconfiguredItems) { var sequenceId = indexGenerator.GetNextSequenceValue(context); item.Id = sequenceId; context.CatalogItems.Add(item); } context.SaveChanges(); }
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 AddCatalogItems(CatalogDBContext context) { var preconfiguredItems = _dataSettings.UseCustomizationData ? GetCatalogItemsFromFile(context) : PreconfiguredData.GetPreconfiguredCatalogItems(); foreach (var item in preconfiguredItems) { if (context.CatalogItems.FirstOrDefault(x => x.Name.Equals(item.Name)) == null) { item.Id = 0; context.CatalogItems.Add(item); } } context.SaveChanges(); }
private void AddCatalogTypes(CatalogDBContext context) { var preconfiguredTypes = useCustomizationData ? GetCatalogTypesFromFile() : PreconfiguredData.GetPreconfiguredCatalogTypes(); int sequenceId = GetSequenceIdFromSelectedDBSequence(context, DBCatalogSequenceName); foreach (var type in preconfiguredTypes) { type.Id = sequenceId; context.CatalogTypes.Add(type); 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(); }
private void AddCatalogTypes(CatalogDBContext context) { var preconfiguredTypes = _dataSettings.UseCustomizationData ? GetCatalogTypesFromFile() : PreconfiguredData.GetPreconfiguredCatalogTypes(); foreach (var type in preconfiguredTypes) { if (context.CatalogTypes.FirstOrDefault(x => x.Id.Equals(type.Id)) == null) { type.Id = type.Id; context.CatalogTypes.Add(type); } } context.SaveChanges(); }
private IEnumerable <CatalogType> GetCatalogTypesFromFile() { string csvFileCatalogTypes = Path.Combine(_webHostEnvironment.ContentRootPath, "Setup", "CatalogTypes.csv"); if (!File.Exists(csvFileCatalogTypes)) { return(PreconfiguredData.GetPreconfiguredCatalogTypes()); } string[] csvheaders; string[] requiredHeaders = { "catalogtype" }; csvheaders = GetHeaders(csvFileCatalogTypes, requiredHeaders); return(File.ReadAllLines(csvFileCatalogTypes) .Skip(1) // skip header row .Select(x => CreateCatalogType(x)) .Where(x => x != null)); }
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)); }
static IEnumerable <CatalogItem> GetCatalogItemsFromFile(CatalogDBContext context) { var contentRootPath = HostingEnvironment.ApplicationPhysicalPath; string csvFileCatalogItems = Path.Combine(contentRootPath, "Setup", "CatalogItems.csv"); if (!File.Exists(csvFileCatalogItems)) { return(PreconfiguredData.GetPreconfiguredCatalogItems()); } string[] csvheaders; string[] requiredHeaders = { "catalogtypename", "catalogbrandname", "description", "name", "price", "pictureFileName" }; string[] optionalheaders = { "availablestock", "restockthreshold", "maxstockthreshold", "onreorder" }; csvheaders = GetHeaders(csvFileCatalogItems, requiredHeaders, optionalheaders); var catalogTypeIdLookup = context.CatalogTypes.ToDictionary(ct => ct.Type, ct => ct.Id); var catalogBrandIdLookup = context.CatalogBrands.ToDictionary(ct => ct.Brand, ct => ct.Id); return(File.ReadAllLines(csvFileCatalogItems) .Skip(1) // skip header row .Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")) .Select(column => CreateCatalogItem(column, csvheaders, catalogTypeIdLookup, catalogBrandIdLookup)) .Where(x => x != null)); }