コード例 #1
0
        public ActionResult Index(PreQualifiedQuestionTemplateModelFilter filter = null, int pageNumner = 1)
        {
            int totalRecords = 0;
            var model        = _preQualifiedQuestionTemplateService.GetPreQualifiedQuestionTemplateListModel(filter, _pageSize, out totalRecords, pageNumner);

            var currentAction          = ControllerContext.RouteData.Values["action"].ToString();
            Func <int, string> urlFunc = pn => Url.Action(currentAction, new { pageNumber = pn, filter.Name, filter.TestId });

            model.PagingModel = new PagingModel(pageNumner, _pageSize, totalRecords, urlFunc);

            return(View(model));
        }
コード例 #2
0
        public IEnumerable <PreQualificationTestTemplate> GetByFilters(PreQualifiedQuestionTemplateModelFilter filter, int pageNumber, int pageSize, out int totalRecords)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData = new LinqMetaData(adapter);

                var query = linqMetaData.PreQualificationTestTemplate.Where(x => x.IsActive == true);

                if (!string.IsNullOrEmpty(filter.Name))
                {
                    query = query.Where(x => x.TemplateName.Contains(filter.Name));
                }

                if (filter.TestId > 0)
                {
                    query = query.Where(x => x.TestId == filter.TestId);
                }

                totalRecords = query.Count();
                var entities = query.OrderByDescending(p => p.IsActive).OrderBy(p => p.TemplateName).TakePage(pageNumber, pageSize).ToArray();

                return(Mapper.Map <IEnumerable <PreQualificationTestTemplateEntity>, IEnumerable <PreQualificationTestTemplate> >(entities));
            }
        }
コード例 #3
0
        public PreQualifiedQuestionTemplateListModel GetPreQualifiedQuestionTemplateListModel(PreQualifiedQuestionTemplateModelFilter filter, int pageSize, out int totalRecords, int pageNumber = 1)
        {
            var templates      = _preQualificationTestTemplateRepository.GetByFilters(filter, pageNumber, pageSize, out totalRecords);
            var dependentTests = _preQualificationTemplateDependentTestRepository.GetByTemplateIds(templates.Select(x => x.Id).ToArray());
            var testIds        = templates.Select(x => x.TestId).Concat(dependentTests.Select(x => x.TestId));
            var tests          = _testRepository.GetTestByIds(testIds);
            var list           = new List <PreQualifiedQuestionTemplateViewModel>();

            foreach (var template in templates)
            {
                var testName = "N/A";

                var test = tests.FirstOrDefault(x => x.Id == template.TestId);
                if (test != null)
                {
                    testName = test.Name;
                }

                var templateDependentTestIds = dependentTests.Where(x => x.TemplateId == template.Id).Select(x => x.TestId);
                var templateDependentTests   = tests.Where(x => templateDependentTestIds.Contains(x.Id)).Select(x => x.Name).ToArray();

                list.Add(new PreQualifiedQuestionTemplateViewModel
                {
                    Name           = template.TemplateName,
                    TestName       = testName,
                    Id             = template.Id,
                    IsActive       = template.IsActive,
                    IsPublished    = template.IsPublished,
                    DependentTests = !templateDependentTests.IsNullOrEmpty() ? string.Join(", ", templateDependentTests) : string.Empty
                });
            }
            return(new PreQualifiedQuestionTemplateListModel
            {
                Filter = filter,
                Templates = list
            });
        }