public void Configure(EntityTypeBuilder <CatalogItem> builder) { builder.ToTable("Catalog"); builder.HasKey(ci => ci.Id); builder.Property(ci => ci.Name) .IsRequired() .HasMaxLength(50); builder.Property(ci => ci.Price) .IsRequired(); builder.Property(ci => ci.PictureFileName) .IsRequired(); builder.Ignore(ci => ci.PictureUri); builder.HasOne(ci => ci.CatalogBrand) .WithMany() .HasForeignKey(ci => ci.CatalogBrandId); builder.HasOne(ci => ci.CatalogType) .WithMany() .HasForeignKey(ci => ci.CatalogTypeId); builder.HasData( PreconfiguredData.GetPreconfiguredCatalogItems() ); }
public CatalogServiceMock() { catalogItems = new List <CatalogItem>(PreconfiguredData.GetPreconfiguredCatalogItems()); catalogBrands = new List <CatalogBrand>(PreconfiguredData.GetPreconfiguredCatalogBrands()); catalogTypes = new List <CatalogType>(PreconfiguredData.GetPreconfiguredCatalogTypes()); catalogItemsStock = new List <CatalogItemsStock>(PreconfiguredData.GetPreconfiguredCatalogItemsStock()); }
private List <CatalogItem> ComposeCatalogItems(List <CatalogItem> items) { var catalogTypes = PreconfiguredData.GetPreconfiguredCatalogTypes(); var catalogBrands = PreconfiguredData.GetPreconfiguredCatalogBrands(); items.ForEach(i => i.CatalogBrand = catalogBrands.First(b => b.Id == i.CatalogBrandId)); items.ForEach(i => i.CatalogType = catalogTypes.First(b => b.Id == i.CatalogTypeId)); return(items); }
private List <CatalogItem> ComposeCatalogItems(List <CatalogItem> items) { var catalogTypes = PreconfiguredData.GetPreconfiguredCatalogTypes(); var catalogManufacturers = PreconfiguredData.GetPreconfiguredCatalogManufacturers(); items.ForEach(i => i.CatalogManufacturer = catalogManufacturers.First(m => m.Id == i.CatalogManufacturerId)); items.ForEach(i => i.CatalogType = catalogTypes.First(t => t.Id == i.CatalogTypeId)); items.ForEach(i => i.CatalogItemSpecs = catalogItemSpecs.First(s => s.Id == i.CatalogItemSpecsId)); return(items); }
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(); }
public void Configure(EntityTypeBuilder <CatalogBrand> builder) { builder.ToTable("CatalogBrand"); builder.HasKey(ci => ci.Id); builder.Property(ci => ci.Id) .IsRequired(); builder.Property(cb => cb.Brand) .IsRequired() .HasMaxLength(100); builder.HasData( PreconfiguredData.GetPreconfiguredCatalogBrands() ); }
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(); }
IEnumerable <CatalogBrand> GetCatalogBrandsFromFile() { var contentRootPath = GetContentRootPath(); 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)); }
IEnumerable <CatalogItem> GetCatalogItemsFromFile(CatalogDBContext context) { var contentRootPath = GetContentRootPath(); 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)); }
public IEnumerable <CatalogBrand> GetCatalogBrands() { return(PreconfiguredData.GetPreconfiguredCatalogBrands()); }
public IEnumerable <CatalogType> GetCatalogTypes() { return(PreconfiguredData.GetPreconfiguredCatalogTypes()); }
public CatalogServiceMock() { catalogItems = new List <CatalogItem>(PreconfiguredData.GetPreconfiguredCatalogItems()); }
public IEnumerable <CatalogItemSpecs> GetAllCatalogItemSpecs(int catalogItemId) { return(PreconfiguredData.GetPreconfiguredCatalogItemSpecs()); }
// GET api/values/5 public CatalogItem Get(int id) { return(PreconfiguredData.GetPreconfiguredCatalogItems().FirstOrDefault(x => x.Id == id)); }
public IEnumerable <CatalogManufacturer> GetCatalogManufacturers() { return(PreconfiguredData.GetPreconfiguredCatalogManufacturers()); }
public CatalogServiceTest() { catalogItems = new List <CatalogItem>(PreconfiguredData.GetPreconfiguredCatalogItems()); catalogItemSpecs = new List <CatalogItemSpecs>(PreconfiguredData.GetPreconfiguredCatalogItemSpecs()); }