public async Task <ItemListModel <ProjectDTO> > GetAsync(ProjectSearchParametersModel parameters) { IQueryable <Project> query = _queryBuilder.SetBaseProjectsInfo() .SetUserId(parameters.UserId) .SetProjectId(parameters.ProjectId) .SetSearchTerm(parameters.SearchTerm) .SetIsActive(parameters.IsActive) .OrderByCreatedDesc() .Build(); Int32 totalCount = await query.CountAsync(); if (parameters.Page != 0) { query = query.Skip((parameters.Page - 1) * parameters.PerPage); } query = query.Take(parameters.PerPage); return(new ItemListModel <ProjectDTO> { Items = _mapper.Map <List <ProjectDTO> >(query.ToList()), TotalCount = totalCount }); }
public async Task Should_Return_Projects_Count_According_To_Filter_Parameters( ProjectSearchParametersModel parameters, Int32 expectedCount) { using (WavesDbContext context = new WavesDbContext(_fixture.DbOptions)) { IProjectStore store = _GetProjectStore(context); ItemListModel <ProjectDTO> result = await store.GetAsync(parameters); Assert.Equal(expectedCount, result.TotalCount); } }
public async Task <IActionResult> Get([FromQuery] ProjectSearchParametersModel parameters) { parameters.UserId = await _GetCurrentUserId(); return(Ok(await _projectStore.GetAsync(parameters))); }