Ejemplo n.º 1
0
        public async Task <IHttpActionResult> GetPagedWall(int wallId, int page = 1)
        {
            if (wallId <= 0)
            {
                return(BadRequest());
            }

            try
            {
                var userAndOrg = GetUserAndOrganization();
                var wallPosts  = await _wallService.GetWallPosts(page, ConstWebApi.DefaultPageSize, userAndOrg, wallId);

                var mappedPosts    = _mapper.Map <IEnumerable <WallPostViewModel> >(wallPosts);
                var pagedViewModel = new PagedWallViewModel <WallPostViewModel>
                {
                    PagedList = mappedPosts.ToPagedList(1, ConstWebApi.DefaultPageSize),
                    PageSize  = ConstWebApi.DefaultPageSize
                };
                return(Ok(pagedViewModel));
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> GetPagedWall(int wallId, int page = 1)
        {
            if (wallId <= 0)
            {
                return(BadRequest());
            }

            try
            {
                var userAndOrg = GetUserAndOrganization();
                var wall       = await _wallService.GetWall(wallId, userAndOrg);

                if (!_permissionService.UserHasPermission(userAndOrg, BasicPermissions.Post) && wall.Type != WallType.Events)
                {
                    return(Forbidden());
                }

                var wallPosts = await _wallService.GetWallPosts(page, WebApiConstants.DefaultPageSize, userAndOrg, wallId);

                var mappedPosts    = _mapper.Map <IEnumerable <WallPostViewModel> >(wallPosts);
                var pagedViewModel = new PagedWallViewModel <WallPostViewModel>
                {
                    PagedList = mappedPosts.ToPagedList(1, WebApiConstants.DefaultPageSize),
                    PageSize  = WebApiConstants.DefaultPageSize
                };
                return(Ok(pagedViewModel));
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }
        }
Ejemplo n.º 3
0
        public async Task Wall_GetPagedWall_Should_Return_View_Model()
        {
            var wallId = 1;
            var page   = 1;

            IEnumerable <PostDTO> posts = new List <PostDTO>
            {
                new PostDTO
                {
                    Id = 0
                },
                new PostDTO
                {
                    Id = 1
                }
            };

            _wallService.GetWall(wallId, null).Returns(new WallDto {
                Type = WallType.UserCreated
            });
            _wallService.GetWallPosts(page, WebApiConstants.DefaultPageSize, null, wallId).ReturnsForAnyArgs(Task.Run(() => posts));

            var response = await _wallController.GetPagedWall(wallId, page);

            Assert.IsInstanceOf <OkNegotiatedContentResult <PagedWallViewModel <WallPostViewModel> > >(response);
        }