// GET api/assessments
        public PagedModel <AssessmentModel> GetAll(int page = 1)
        {
            if (page < 1)
            {
                page = 1;
            }

            var pagedAssessments = manager.GetAll(page: page, pageSize: PAGE_SIZE);

            var helper = new UrlHelper(Request);

            var links = new List <LinkModel>();

            if (page > 1 && (page - 1) < pagedAssessments.TotalPages)
            {
                links.Add(TheModelFactory.CreateLink(helper.Link("Assessments", new { page = page - 1 }), "prevPage"));
            }

            if (page < pagedAssessments.TotalPages)
            {
                links.Add(TheModelFactory.CreateLink(helper.Link("Assessments", new { page = page + 1 }), "nextPage"));
            }

            return(new PagedModel <AssessmentModel>()
            {
                TotalRecords = pagedAssessments.TotalRecords,
                TotalPages = pagedAssessments.TotalPages,
                Links = links,
                PagedData = pagedAssessments.PagedData.Select(a => TheModelFactory.Create(a)).ToList()
            });
        }
Esempio n. 2
0
        public ActionResult GetAllEntities()
        {
            OperateResult or = AssessmentManager.GetAll();

            if (or.status == OperateStatus.Success &&
                or.data != null)
            {
                return(Json(or.data, JsonRequestBehavior.AllowGet));
            }


            return(Json(or, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public void Get_All_Returns_AllAssessments()
        {
            // Arrange
            InitAssessmentCategoriesNew(assessmentRepository);
            assessmentManager = new AssessmentManager(null, assessmentRepository.Object, null);

            //// Act
            var pagedAssessments = assessmentManager.GetAll(page: 1, pageSize: 3);

            //// Assert
            Assert.IsNotNull(pagedAssessments, "Result is null");
            Assert.IsInstanceOfType(pagedAssessments, typeof(PagedEntity <Assessment>), "Wrong Model");
            Assert.AreEqual(4, pagedAssessments.TotalRecords, "Wrong number of record count");
            Assert.AreEqual(4, pagedAssessments.PagedData.Count, "Got wrong number of Assessments");
        }