public async Task <IHttpActionResult> CreatePost(CreateWallPostViewModel wallPostViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var postModel = _mapper.Map <CreateWallPostViewModel, NewPostDTO>(wallPostViewModel); SetOrganizationAndUser(postModel); try { var createdPost = _postService.CreateNewPost(postModel); var membersToNotify = _userService.GetWallUserAppNotificationEnabledIds(postModel.UserId, postModel.WallId); var notificationDto = await _notificationService.CreateForPost(GetUserAndOrganization(), createdPost, postModel.WallId, membersToNotify); NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationDto), GetUserAndOrganizationHub(), membersToNotify); NotificationHub.SendWallNotification(wallPostViewModel.WallId, membersToNotify, createdPost.WallType, GetUserAndOrganizationHub()); return(Ok(_mapper.Map <WallPostViewModel>(createdPost))); } catch (ValidationException e) { return(BadRequestWithError(e)); } }
public IHttpActionResult CreatePost(CreateWallPostViewModel wallPostViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } 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)); } }
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)); } }