// // Seleciona o produto, por categoria ou todos, seta a paginação e a ordenação e devolve os dados // para um DataTable, ideal para gridView com Ordenação por categoria. Tem de ser utilizado com // o método COUNT abaixo // public IList GetInventories(int companyId, int depositId, int?categoryId, bool categoriesRecursive, string sortExpression, int startRowIndex, int maximumRows) { var productManager = new ProductManager(this); var categoryManager = new CategoryManager(this); var query = from inventory in DbContext.Inventories join product in productManager.GetAllProducts() on inventory.ProductId equals product.ProductId join category in categoryManager.GetChildCategories(companyId, categoryId, categoriesRecursive) on product.CategoryId equals category.CategoryId join manufacturer in DbContext.Manufacturers on product.ManufacturerId equals manufacturer.ManufacturerId into gManufactory from manufacturer in gManufactory.DefaultIfEmpty() where product.CompanyId == companyId && inventory.DepositId == depositId select new { inventory, product.ProductId, product.Name, product.ProductCode, product.ModifiedDate, product.CompanyId, product.BarCode, product.CategoryId, product.IsActive, product.ManufacturerId, product.BarCodeTypeId, product.Description, product.DropCompositeInStock, product.AddCustomerEquipmentInSale, product.AllowNegativeStock, product.AllowSaleBelowCost, product.IPI, product.ICMS, product.FiscalClass, product.WarrantyDays, product.IdentificationOrPlaca, product.PatrimonioOrRenavam, product.SerialNumberOrChassi, ImageUrl = product.ProductImages.Count > 0 ? product.ProductImages.FirstOrDefault().ImageUrl : "", ManufacturerName = manufacturer.Name ?? "", CategoryName = category.Name }; //if (categoryId.HasValue) // query = query.Where(x => x.CategoryId == categoryId); return(query.SortAndPage(sortExpression, startRowIndex, maximumRows, "Name").ToList()); }