public IHttpActionResult List([FromUri] ProjectTasksRequestDto request) { if (!_repository.All.Any(c => c.Id == request.ProjectId)) { ModelState.AddModelError(nameof(request.ProjectId), "Project with such identifier doesn't exist."); } if (request.Status.HasValue && !_repository.DoesProjectHaveStatus(request.ProjectId, request.Status.Value)) { ModelState.AddModelError(nameof(request.Status), "Invalid status for specified project."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var query = request.Status.HasValue ? _repository.GetTasks(request.ProjectId, request.Status.Value) : _repository.GetTasks(request.ProjectId); return(Ok(query.OrderBy(c => c.Id) .Paginate(request.PageSize, request.PageNumber) .ProjectTo <ProjectTaskDto>(_mapper.ConfigurationProvider) .ToList())); }