public IActionResult GetAll(bool paging = false, int pageNumber = 1, int questionsPerPage = 10, int labelId = 0, int difficultyId = 0) { IList <Question> questions = null; Expression <Func <Question, bool> > predicate = q => q.IsActive != false; if (labelId != 0) { Expression <Func <Question, bool> > labelPredicate = q => q.Label.Id == labelId; predicate = PredicateHelper.CombineWithAnd(predicate, labelPredicate); } if (difficultyId != 0) { Expression <Func <Question, bool> > difficultyPredicate = q => q.Difficulty.Id == difficultyId; predicate = PredicateHelper.CombineWithAnd(predicate, difficultyPredicate); } IList <Question> totalQuestions = _questionRepository. AllIncluding(q => q.Label, q => q.Difficulty, q => q.Options, q => q.QuestionGroup). Where(predicate). OrderByDescending(q => q.CreatedUtc).ToList(); if (paging == true) { questions = totalQuestions. Skip((pageNumber - 1) * questionsPerPage). Take(questionsPerPage). ToList(); } else { questions = totalQuestions.ToList(); } var qDtos = Mapper.Map <IList <QuestionDto> >(questions); if (paging == true) { return(Ok(new { totalPages = Math.Ceiling((double)totalQuestions.Count / questionsPerPage), questions = qDtos, totalQuestions = totalQuestions.Count })); } else { return(Ok(qDtos)); } }