GetWideWorldImportersDbContext(string dbName) { // Create options for DbContext instance var options = new DbContextOptionsBuilder <WideWorldImportersDbContext>() .UseInMemoryDatabase(databaseName: dbName) .Options; // Create instance of DbContext var dbContext = new WideWorldImportersDbContext(options); // Add entities in memory dbContext.Seed(); return(dbContext); }
public static IQueryable <StockItem> GetStockItems(this WideWorldImportersDbContext dbContext, int pageSize = 10, int pageNumber = 1, int?lastEditedBy = null, int?colorID = null, int?outerPackageID = null, int?supplierID = null, int?unitPackageID = null) { // Get query from DbSet var query = dbContext.StockItems.AsQueryable(); // Filter by: 'LastEditedBy' if (lastEditedBy.HasValue) { query = query.Where(item => item.LastEditedBy == lastEditedBy); } // Filter by: 'ColorID' if (colorID.HasValue) { query = query.Where(item => item.ColorID == colorID); } // Filter by: 'OuterPackageID' if (outerPackageID.HasValue) { query = query.Where(item => item.OuterPackageID == outerPackageID); } // Filter by: 'SupplierID' if (supplierID.HasValue) { query = query.Where(item => item.SupplierID == supplierID); } // Filter by: 'UnitPackageID' if (unitPackageID.HasValue) { query = query.Where(item => item.UnitPackageID == unitPackageID); } return(query); }
public static void Seed(this WideWorldImportersDbContext dbContext) { // Add entities for DbContext instance dbContext.StockItems.Add(new StockItem { StockItemID = 1, StockItemName = "USB missile launcher (Green)", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 25.00m, RecommendedRetailPrice = 37.38m, TypicalWeightPerUnit = 0.300m, MarketingComments = "Complete with 12 projectiles", CustomFields = "{ \"CountryOfManufacture\": \"China\", \"Tags\": [\"USB Powered\"] }", Tags = "[\"USB Powered\"]", SearchDetails = "USB missile launcher (Green) Complete with 12 projectiles", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 2, StockItemName = "USB rocket launcher (Gray)", SupplierID = 12, ColorID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 25.00m, RecommendedRetailPrice = 37.38m, TypicalWeightPerUnit = 0.300m, MarketingComments = "Complete with 12 projectiles", CustomFields = "{ \"CountryOfManufacture\": \"China\", \"Tags\": [\"USB Powered\"] }", Tags = "[\"USB Powered\"]", SearchDetails = "USB rocket launcher (Gray) Complete with 12 projectiles", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 3, StockItemName = "Office cube periscope (Black)", SupplierID = 12, ColorID = 3, UnitPackageID = 7, OuterPackageID = 6, LeadTimeDays = 14, QuantityPerOuter = 10, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 18.50m, RecommendedRetailPrice = 27.66m, TypicalWeightPerUnit = 0.250m, MarketingComments = "Need to see over your cubicle wall? This is just what's needed.", CustomFields = "{ \"CountryOfManufacture\": \"China\", \"Tags\": [] }", Tags = "[]", SearchDetails = "Office cube periscope (Black) Need to see over your cubicle wall? This is just what's needed.", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 4, StockItemName = "USB food flash drive - sushi roll", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"32GB\",\"USB Powered\"] }", Tags = "[\"32GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - sushi roll ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 5, StockItemName = "USB food flash drive - hamburger", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"16GB\",\"USB Powered\"] }", Tags = "[\"16GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - hamburger ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 6, StockItemName = "USB food flash drive - hot dog", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"32GB\",\"USB Powered\"] }", Tags = "[\"32GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - hot dog ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 7, StockItemName = "USB food flash drive - pizza slice", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"16GB\",\"USB Powered\"] }", Tags = "[\"16GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - pizza slice ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 8, StockItemName = "USB food flash drive - dim sum 10 drive variety pack", SupplierID = 12, UnitPackageID = 9, OuterPackageID = 9, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 240.00m, RecommendedRetailPrice = 358.80m, TypicalWeightPerUnit = 0.500m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"32GB\",\"USB Powered\"] }", Tags = "[\"32GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - dim sum 10 drive variety pack ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 9, StockItemName = "USB food flash drive - banana", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"16GB\",\"USB Powered\"] }", Tags = "[\"16GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - banana ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 10, StockItemName = "USB food flash drive - chocolate bar", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"32GB\",\"USB Powered\"] }", Tags = "[\"32GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - chocolate bar ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 11, StockItemName = "USB food flash drive - cookie", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"16GB\",\"USB Powered\"] }", Tags = "[\"16GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - cookie ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.StockItems.Add(new StockItem { StockItemID = 12, StockItemName = "USB food flash drive - donut", SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"32GB\",\"USB Powered\"] }", Tags = "[\"32GB\",\"USB Powered\"]", SearchDetails = "USB food flash drive - donut ", LastEditedBy = 1, ValidFrom = new DateTime(2016, 5, 31, 23, 11, 0), ValidTo = new DateTime(9999, 12, 31, 23, 59, 59) }); dbContext.SaveChanges(); }
public WarehouseController(ILogger <WarehouseController> logger, WideWorldImportersDbContext dbContext) { Logger = logger; DbContext = dbContext; }
public PeopleController( WideWorldImportersDbContext dbContext) { _dbContext = dbContext; }
public static async Task <StockItem> GetStockItemsByStockItemNameAsync(this WideWorldImportersDbContext dbContext, StockItem entity) => await dbContext.StockItems.FirstOrDefaultAsync(item => item.StockItemName == entity.StockItemName);