public virtual async Task <IPagedDataTables <T> > GetPagedListAsync( string sortColumnName, SortDirection sortDirection, int page = 0, int size = 0) { var query = QueryNoTracking(); int totalRecords = await query.CountAsync(); if (totalRecords == 0) { return(PagedDataTables <T> .Empty()); } int totalRecordsFiltered = totalRecords; query = OrderBy(query, sortColumnName, sortDirection); if (page > 0 && size > 0) { query = query.Skip(page).Take(size); } return(PagedDataTables <T> .Create(query, totalRecords, totalRecordsFiltered)); }
public async Task <IPagedDataTables <ActivityLog> > GetPagedListAsync( DateTime fromDate, DateTime toDate, string userName, string ip, string sortColumnName, SortDirection sortDirection, int page, int size) { int totalRecords = await QueryNoTracking().CountAsync(); if (totalRecords == 0) { return(PagedDataTables <ActivityLog> .Empty()); } var query = _dbSet .Include(al => al.ActivityLogType) .Include(al => al.ApplicationUser) .AsNoTracking(); if (fromDate != DateTime.MinValue && toDate != DateTime.MinValue && fromDate <= toDate) { DateTime startDate = fromDate.StartOfDay(); DateTime endDate = toDate.EndOfDay(); query = query.Where(al => startDate <= al.CreatedOn && al.CreatedOn <= endDate); } if (!string.IsNullOrWhiteSpace(userName)) { query = query.Where(al => al.ApplicationUser.UserName.StartsWith(userName)); } if (!string.IsNullOrWhiteSpace(ip)) { query = query.Where(al => al.IP.StartsWith(ip)); } int totalRecordsFiltered = await query.CountAsync(); if (totalRecordsFiltered == 0) { return(PagedDataTables <ActivityLog> .Empty(totalRecords)); } query = OrderBy(query, sortColumnName, sortDirection).Skip(page).Take(size); return(PagedDataTables <ActivityLog> .Create(query, totalRecords, totalRecordsFiltered)); }
public async Task <IPagedDataTables <Log> > GetPagedListAsync( DateTime fromDate, DateTime toDate, string[] levels, string sortColumnName, SortDirection sortDirection, int page, int size) { var query = QueryNoTracking(); int totalRecords = await query.CountAsync(); if (totalRecords == 0) { return(PagedDataTables <Log> .Empty()); } if (fromDate != DateTime.MinValue && toDate != DateTime.MinValue && fromDate <= toDate) { DateTime startDate = fromDate.StartOfDay(); DateTime endDate = toDate.EndOfDay(); query = query.Where(l => startDate <= l.Logged && l.Logged <= endDate); } if (levels != null && levels.Length > 0) { query = query.Where(l => levels.Contains(l.Level)); } int totalRecordsFiltered = await query.CountAsync(); if (totalRecordsFiltered == 0) { return(PagedDataTables <Log> .Empty(totalRecords)); } query = OrderBy(query, sortColumnName, sortDirection).Skip(page).Take(size); return(PagedDataTables <Log> .Create(query, totalRecords, totalRecordsFiltered)); }