public async Task <IActionResult> Index(FAQSearchViewModel searchModel)
        {
            ViewBag.FaqGroups = _faqGroupRepository.GetAllMap <FaqGroupDTO>();

            var model = await _fAQRepository.LoadAsyncCount(
                this.CurrentPage,
                this.PageSize,
                searchModel);

            this.TotalNumber = model.Item1;

            ViewBag.SearchModel = searchModel;

            return(View(model.Item2));
        }
Exemple #2
0
        public async Task <Tuple <int, List <FAQDTO> > > LoadAsyncCount(
            int skip = -1,
            int take = -1,
            FAQSearchViewModel model = null)
        {
            var query = Entities.ProjectTo <FAQDTO>();

            if (!string.IsNullOrEmpty(model.QuestionText))
            {
                query = query.Where(x => x.QuestionText.Contains(model.QuestionText));
            }


            if (!string.IsNullOrEmpty(model.AnswerText))
            {
                query = query.Where(x => x.AnswerText.Contains(model.AnswerText));
            }

            if (model.FaqGroupId != null && model.FaqGroupId != 0)
            {
                query = query.Where(x => x.FaqGroupId == model.FaqGroupId);
            }


            if (model.IsActive != null)
            {
                query = query.Where(x => x.IsActive == model.IsActive);
            }


            int Count = query.Count();

            query = query.OrderByDescending(x => x.Id);


            if (skip != -1)
            {
                query = query.Skip((skip - 1) * take);
            }

            if (take != -1)
            {
                query = query.Take(take);
            }

            return(new Tuple <int, List <FAQDTO> >(Count, await query.ToListAsync()));
        }