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 async Task <StockItem> GetStockItemsByStockItemNameAsync(this WideWorldImportersDbContext dbContext, StockItem entity) => await dbContext.StockItems.FirstOrDefaultAsync(item => item.StockItemName == entity.StockItemName);