public static IQueryable <Product> GetProductList(this TeamBleemsDbContext dbContext, int pageSize = 10, int pageNumber = 1, string productName = null, int?categoryID = null, int?isAll = 0) { // Get query from DbSet var query = dbContext.Product.AsQueryable(); // Filter by: 'category' if (categoryID.HasValue) { query = query.Where(item => item.categoryId == categoryID); } // Filter by: 'productName' if (!string.IsNullOrEmpty(productName)) { query = query.Where(item => item.productName.Contains(productName)); } // Filter by: 'isActive' if (isAll.HasValue) { if (isAll == -1) { query = query.Where(item => item.isActive == false); } else if (isAll == 1) { query = query.Where(item => item.isActive == true); } } return(query); }
public static async Task <Category> GetCategoryAsync(this TeamBleemsDbContext dbContext, Category entity) => await dbContext.Category.FirstOrDefaultAsync(item => item.categoryId == entity.categoryId);
public static async Task <Product> GetProductByProductNameAsync(this TeamBleemsDbContext dbContext, Product entity) => await dbContext.Product.FirstOrDefaultAsync(item => item.productName == entity.productName);