Example #1
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));
            }
        }
        public async Task Wall_GetWall_Should_Return_View_Model()
        {
            var wallId = 1;
            var wall   = new WallDto
            {
                Id = wallId
            };

            _wallService.GetWall(wallId, null).Returns(new WallDto {
                Type = WallType.UserCreated
            });
            _wallService.GetWallDetails(0, null).ReturnsForAnyArgs(Task.Run(() => wall));

            var response = await _wallController.GetWall(wallId);

            Assert.IsInstanceOf <OkNegotiatedContentResult <WallListViewModel> >(response);
        }
Example #3
0
        public async Task <IHttpActionResult> CreatePost(CreateWallPostViewModel wallPostViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userAndOrg = GetUserAndOrganization();

            if (!_permissionService.UserHasPermission(userAndOrg, BasicPermissions.Post))
            {
                var wall = await _wallService.GetWall(wallPostViewModel.WallId, userAndOrg);

                if (wall.Type != WallType.Events)
                {
                    return(Forbidden());
                }
            }

            var postModel = _mapper.Map <CreateWallPostViewModel, NewPostDTO>(wallPostViewModel);

            SetOrganizationAndUser(postModel);
            var userHubDto = GetUserAndOrganizationHub();

            try
            {
                var createdPost = _postService.CreateNewPost(postModel);
                _asyncRunner.Run <NewPostNotifier>(notif =>
                {
                    notif.Notify(createdPost, userHubDto);
                }, GetOrganizationName());

                return(Ok(_mapper.Map <WallPostViewModel>(createdPost)));
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }
        }