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 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)); }