public async Task <IHttpActionResult> GetPost(int postId) { try { var userAndOrg = GetUserAndOrganization(); var wallPost = await _wallService.GetWallPost(userAndOrg, postId); var mappedPost = _mapper.Map <WallPostViewModel>(wallPost); return(Ok(mappedPost)); } catch (ValidationException e) { return(BadRequestWithError(e)); } }
public async Task <IHttpActionResult> GetPost(int postId) { try { var userAndOrg = GetUserAndOrganization(); var wallPost = await _wallService.GetWallPost(userAndOrg, postId); if (!_permissionService.UserHasPermission(userAndOrg, BasicPermissions.Post) && wallPost.WallType != WallType.Events) { return(Forbidden()); } var mappedPost = _mapper.Map <WallPostViewModel>(wallPost); return(Ok(mappedPost)); } catch (ValidationException e) { return(BadRequestWithError(e)); } }
public async Task <IHttpActionResult> CreateComment(NewCommentViewModel comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userAndOrg = GetUserAndOrganization(); var wallPost = await _wallService.GetWallPost(userAndOrg, comment.PostId); if (!_permissionService.UserHasPermission(userAndOrg, BasicPermissions.Comment) && wallPost.WallType != WallType.Events) { return(Forbidden()); } var commentDto = _mapper.Map <NewCommentViewModel, NewCommentDTO>(comment); SetOrganizationAndUser(commentDto); var userHubDto = GetUserAndOrganizationHub(); try { var commentCreatedDto = _commentService.CreateComment(commentDto); _asyncRunner.Run <NewCommentNotifier>(notif => { notif.Notify(commentCreatedDto, userHubDto); }, GetOrganizationName()); return(Ok(new { commentCreatedDto.CommentId })); } catch (ValidationException e) { return(BadRequestWithError(e)); } }