示例#1
0
        public async Task <IHttpActionResult> GetPost(int postId)
        {
            try
            {
                var userAndOrg = GetUserAndOrganization();
                var wallPost   = await _wallService.GetWallPostAsync(userAndOrg, postId);

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

                var mappedPost = _mapper.Map <WallPostViewModel>(wallPost);
                return(Ok(mappedPost));
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }
        }
示例#2
0
        public async Task <IHttpActionResult> CreateComment(NewCommentViewModel comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userAndOrg = GetUserAndOrganization();

            var wallPost = await _wallService.GetWallPostAsync(userAndOrg, comment.PostId);

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

            var commentDto = _mapper.Map <NewCommentViewModel, NewCommentDto>(comment);

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

            try
            {
                var commentCreatedDto = await _commentService.CreateCommentAsync(commentDto);

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

                return(Ok(new { commentCreatedDto.CommentId }));
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }
        }