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.GetWallAsync(wallId, userAndOrg);

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

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

                var mappedPosts    = _mapper.Map <IEnumerable <WallPostViewModel> >(wallPosts);
                var pagedViewModel = new PagedWallViewModel <WallPostViewModel>
                {
                    PagedList = await mappedPosts.ToPagedListAsync(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.GetWallAsync(wallId, null).Returns(new WallDto {
                Type = WallType.UserCreated
            });
            _wallService.GetWallDetailsAsync(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 (!await _permissionService.UserHasPermissionAsync(userAndOrg, BasicPermissions.Post))
            {
                var wall = await _wallService.GetWallAsync(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 = await _postService.CreateNewPostAsync(postModel);

                _asyncRunner.Run <NewPostNotifier>(async notifier =>
                {
                    await notifier.NotifyAsync(createdPost, userHubDto);
                }, GetOrganizationName());

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