public async Task <List <WorkLog> > GetWorkLogs(GetWorkLogsInput input) { IQueryable <WorkLog> query = _context.WorkLogs; // User Filtering if (input.UserId.Length == 0 || input.UserId == "UnAssigned") { input.UserId = _httpContextAccessor?.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; } query = (string.IsNullOrEmpty(input.UserId) || input.UserId == "AllUsers") ? query : query.Where(s => s.UserId == input.UserId); // CodeHub Filtering query = BuildCodeHubQuery(input, query); // Generic Filtering query = (input.OrganizationId == 0) ? query : query.Where(s => s.OrganizationId == input.OrganizationId); query = string.IsNullOrEmpty(input.DescriptionFilter) ? query : query.Where(s => s.Description.Contains(input.DescriptionFilter)); // Date Filtering query = query.Where(s => (s.DateStarted.Date >= input.SearchStartDate.Date || s.DateFinished.Date >= input.SearchStartDate.Date) && (s.DateStarted.Date <= input.SearchEndDate.Date || s.DateFinished.Date <= input.SearchEndDate.Date)); query = query.OrderBy(s => s.DateStarted.Date); return(await query.ToListAsync()); }
public IQueryable <WorkLog> BuildCodeHubQuery(GetWorkLogsInput input, IQueryable <WorkLog> query) { //query = (!input.IncludeEpics && !input.IncludeProjects && !input.IncludeOrganizations) ? query : query.Include(log => log.Epic ?? new Epic()).ThenInclude(epic => epic.Project ?? new Project()).ThenInclude(project => project.Organization ?? new Organization()); query = (!input.IncludeEpics && !input.IncludeProjects && !input.IncludeOrganizations) ? query : query.Include(log => log.Epic.Project.Organization); query = (input.EpicId == 0) ? query : query.Where(s => s.Epic != null).Where(s => s.EpicId == input.EpicId); query = (input.ProjectId == 0) ? query : query.Where(s => s.Epic != null).Where(s => s.Epic.ProjectId == input.ProjectId); return(query); }