public async Task <List <SystemActivityDTO> > GetSystemReport([FromQuery] SystemReportFilterCriteria filter) { var command = new GetSystemReportQuery(filter); var result = await _queryProcessor.Process(command); return(result); }
public async void given_GetSystemReportQuery_queryprocessor_should_get_same_query_created_in_controller() { //Assemble var mockAgg = new UserControllerMockAggregate(); var input = new SystemReportFilterCriteria(); mockAgg.setup_processor_to_verify_getSystemReportQueries_are_the_same(); var controller = mockAgg.CreateUserController(); //Apply var result = await controller.GetSystemReport(input); //Assert //Assert.Equal(query, mockAgg.PermissionQuery); Assert.IsType <List <SystemActivityDTO> >(result); }
private async Task <List <SystemActivityProjection> > Filter(SystemReportFilterCriteria criteria) { IQueryable <SystemActivityProjection> query = _context.SystemActivityProjection; if (!String.IsNullOrWhiteSpace(criteria.SearchTerms)) { criteria.SearchTerms = criteria.SearchTerms.ToLower(); query = query.Where(a => a.ForFullName.ToLower().Contains(criteria.SearchTerms) || a.PermissionName.ToLower().Contains(criteria.SearchTerms)); } if (criteria.SortDirection == "DSC") { if (criteria.SortField == "ForFullName") { query = query.OrderByDescending(a => a.ForFullName).ThenBy(a => a.Timestamp); } else if (criteria.SortField == "PermissionName") { query = query.OrderByDescending(a => a.PermissionName).ThenBy(a => a.Timestamp); } else { query = query.OrderByDescending(a => a.Timestamp); } } else if (criteria.SortDirection == "ASC") { if (criteria.SortField == "ForFullName") { query = query.OrderBy(a => a.ForFullName).ThenBy(a => a.Timestamp); } else if (criteria.SortField == "PermissionName") { query = query.OrderBy(a => a.PermissionName).ThenBy(a => a.Timestamp); } else { query = query.OrderBy(a => a.Timestamp); } } else { query = query.OrderByDescending(a => a.ForFullName); } if (criteria.PermissionId != Guid.Empty) { query = query.Where(a => a.PermissionId == criteria.PermissionId); } //return all actions within a range that are less than the given date, default date is time of query //when querying, enter a local time, this will take care of conversion from utc to local query = query.Where(a => a.Timestamp <= criteria.EndDate); var list = await query.ToListAsync(); List <SystemActivityProjection> result = new List <SystemActivityProjection>(); foreach (var entry in list) { if (String.Equals(entry.EventType, "Permission Granted")) { result.Add(entry); } if (String.Equals(entry.EventType, "Permission Revoked")) { try { result.RemoveAll(a => a.ForId == entry.ForId && a.PermissionId == entry.PermissionId); } catch (Exception e) { Console.WriteLine(e); } } } return(result); }
public GetSystemReportQuery(SystemReportFilterCriteria filterCriteria) { FilterCriteria = filterCriteria; }