public AuditTrailResult FindEntriesForFilter(AuditTrailFilter filter) { AuditTrailEntriesByFilterQuery query = new AuditTrailEntriesByFilterQuery(dbContext.AuditTrailEntries); List<AuditTrailEntry> filteredResult = query.Execute(filter).ToList(); AuditTrailResult result = new AuditTrailResult(); result.ResultCount = filteredResult.Count(); result.Items.AddRange(filteredResult.Skip((int) filter.Skip).Take((int) filter.Take)); return result; }
public IQueryable<AuditTrailEntry> Execute(AuditTrailFilter filter) { var resultEntries = auditTrailEntries; #region filtering resultEntries = resultEntries.Where( MakeTimestampFilterExpression(filter.TimestampFilterLogic, filter.TimestampFilterParameters) .And(MakeSummaryFilterExpression(filter.SummaryFilterLogic, filter.SummaryFilterParameters)) .And(MakeSubjectNameFilterExpression(filter.SubjectNameFilterLogic, filter.SubjectNameFilterParameters)) .And(MakeUserNameFilterExpression(filter.UserNameFilterLogic, filter.UserNameFilterParameters)) ); #endregion #region ordering foreach (AuditTrailSortParameter sortParam in filter.SortParameters) { switch (sortParam.SortField) { case AuditTrailSortField.TIMESTAMP: if (sortParam.SortDirection == AuditTrailSortDirection.ASC) { resultEntries = resultEntries.OrderBy(e => e.Timestamp); } else { resultEntries = resultEntries.OrderByDescending(e => e.Timestamp); } break; case AuditTrailSortField.SUMMARY: if (sortParam.SortDirection == AuditTrailSortDirection.ASC) { resultEntries = resultEntries.OrderBy(e => e.Summary); } else { resultEntries = resultEntries.OrderByDescending(e => e.Summary); } break; case AuditTrailSortField.SUBJECTNAME: if (sortParam.SortDirection == AuditTrailSortDirection.ASC) { resultEntries = resultEntries.OrderBy(e => e.SubjectName); } else { resultEntries = resultEntries.OrderByDescending(e => e.SubjectName); } break; case AuditTrailSortField.USERNAME: if (sortParam.SortDirection == AuditTrailSortDirection.ASC) { resultEntries = resultEntries.OrderBy(e => e.UserName); } else { resultEntries = resultEntries.OrderByDescending(e => e.UserName); } break; } } #endregion return resultEntries; }