public async Task <PagedList <ActionItemDto> > GetActionItems(ActionItemParams actionItemParams) { var query = _context.ActionItems.Include(x => x.AppUser).AsQueryable(); //query = query.Where(u => u.UserName != userParams.CurrentUsername); if (actionItemParams.WorkOrderTypeRequest != null) { query = query.Where(a => a.WorkOrderTypeRequest == actionItemParams.WorkOrderTypeRequest); } if (actionItemParams.MapStatus != "all") { query = query.Where(a => a.MapStatus == actionItemParams.MapStatus); } if (actionItemParams.ActionItemNumber != null) { query = query.Where(a => a.ActionItemNumber == actionItemParams.ActionItemNumber); } if (actionItemParams.AICreatedBy > 0) { query = query.Where(a => a.AiCreatedBy == actionItemParams.AICreatedBy); } if (actionItemParams.InternalEmailSubject != null) { query = query.Where(a => a.InternalEmailSubject.Contains(actionItemParams.InternalEmailSubject)); } if (actionItemParams.ExternalEmailSubject != null) { query = query.Where(a => a.ExternalEmailSubject.Contains(actionItemParams.ExternalEmailSubject)); } if (actionItemParams.MetSLO != null) { query = (actionItemParams.MetSLO.ToLower() == "yes") ? query.Where(a => a.MetSLO) : query.Where(a => !a.MetSLO); } if (actionItemParams.MetElapsedTarget != null) { query = (actionItemParams.MetElapsedTarget.ToLower() == "yes") ? query.Where(a => a.MetElapsedTarget) : query.Where(a => !a.MetElapsedTarget); } if (actionItemParams.DateStartedFrom != null && actionItemParams.DateStartedTo != null) { var dateStartedFrom = Convert.ToDateTime(actionItemParams.DateStartedFrom, CultureInfo.InvariantCulture).ToLocalTime(); var dateStartedTo = Convert.ToDateTime(actionItemParams.DateStartedTo, CultureInfo.InvariantCulture).ToLocalTime(); query = query.Where(u => u.DateStarted >= dateStartedFrom && u.DateStarted <= dateStartedTo); } if (actionItemParams.DateResolvedFrom != null && actionItemParams.DateResolvedTo != null) { var dateResolvedFrom = Convert.ToDateTime(actionItemParams.DateResolvedFrom, CultureInfo.InvariantCulture).ToLocalTime(); var dateResolvedTo = Convert.ToDateTime(actionItemParams.DateResolvedTo, CultureInfo.InvariantCulture).ToLocalTime(); query = query.Where(u => u.DateResolved >= dateResolvedFrom && u.DateStarted <= dateResolvedTo); } query = actionItemParams.OrderBy switch { "created" => query.OrderByDescending(a => a.DateCreated), _ => query.OrderByDescending(a => a.Id) }; return(await PagedList <ActionItemDto> .CreateAsync(query.ProjectTo <ActionItemDto>(_mapper .ConfigurationProvider).AsNoTracking(), actionItemParams.PageNumber, actionItemParams.PageSize)); }
public async Task <ActionResult <IEnumerable <ActionItemDto> > > GetActionItems([FromQuery] ActionItemParams actionItemParams) { var actionItem = await _actionItemRepository.GetActionItems(actionItemParams); var users = await _userRepository.GetUsers(); actionItem.ForEach(x => { if (x.AiCreatedBy != 0) { var user = users.SingleOrDefault(u => u.Id == x.AiCreatedBy); x.AICreatedByName = $"{user.FirstName} {user.LastName}"; } }); Response.AddPaginationHeader(actionItem.CurrentPage, actionItem.PageSize, actionItem.TotalCount, actionItem.TotalPages); return(Ok(actionItem)); }