public ExpenseCategoryDatatables GetExpenseCategorysForTable(int page, int itemsPerPage, string sortBy, bool reverse, string searchValue) { var expenseCategorys = _expenseCategoryRepository.GetAllQueryable(); // searching if (!string.IsNullOrWhiteSpace(searchValue)) { searchValue = searchValue.ToLower(); expenseCategorys = expenseCategorys.Where(cus => cus.CategoryN.ToLower().Contains(searchValue) || cus.CategoryC.ToLower().Contains(searchValue) ); } // sorting (done with the System.Linq.Dynamic library available on NuGet) //expenseCategorys = expenseCategorys.AsQueryable().OrderBy("\"" + sortBy + (reverse ? " desc\"" : " asc\"")).AsEnumerable(); var expenseCategorysOrdered = expenseCategorys.OrderBy(sortBy + (reverse ? " descending" : "")); // paging var expenseCategorysPaged = expenseCategorysOrdered.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToList(); var destination = Mapper.Map <List <ExpenseCategory_M>, List <ExpenseCategoryViewModel> >(expenseCategorysPaged); var custDatatable = new ExpenseCategoryDatatables() { Data = destination, Total = expenseCategorys.Count() }; return(custDatatable); }
public ExpenseDatatables GetExpensesForTable(int page, int itemsPerPage, string sortBy, bool reverse, string searchValue) { var expenses = (from e in _expenseRepository.GetAllQueryable() join c in _expenseCategoryRepository.GetAllQueryable() on e.CategoryC equals c.CategoryC into t from c in t.DefaultIfEmpty() where (searchValue == null || searchValue == "" || e.ExpenseN.ToLower().Contains(searchValue.ToLower()) || e.ExpenseC.ToLower().Contains(searchValue.ToLower())) select new ExpenseViewModel { ExpenseC = e.ExpenseC, ExpenseN = e.ExpenseN, CategoryI = e.CategoryI, CategoryN = c.CategoryN, Unit = e.Unit, UnitPrice = e.UnitPrice, TaxRate = e.TaxRate, IsIncluded = e.IsIncluded, Description = e.Description, ViewReport = e.ViewReport, ColumnName = e.ColumnName }); // sorting (done with the System.Linq.Dynamic library available on NuGet) //expenses = expenses.AsQueryable().OrderBy("\"" + sortBy + (reverse ? " desc\"" : " asc\"")).AsEnumerable(); var expensesOrdered = expenses.OrderBy(sortBy + (reverse ? " descending" : "")); // paging var expensesPaged = expensesOrdered.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToList(); var custDatatable = new ExpenseDatatables() { Data = expensesPaged.ToList(), Total = expenses.Count() }; return(custDatatable); }