public async Task <IActionResult> AddPostDescription(NewPostRequestDto newPost) { try { var userId = int.Parse(HttpContext.User.Identity.Name); var post = await _postService.AddNewPost(newPost, userId); await _notificationService.AddNewPostNotification(userId); var connections = await _connectionService.GetFriendsConnectionId(userId); var postJson = JsonConvert.SerializeObject(new { postContent = post.PostContent, postId = post.PostId, username = post.PostOwner.Username, postImage = post.PostImage, profilePicture = post.PostOwner.ProfilePicture }); await _hubContext.Clients.Clients(connections).SendAsync("NewPostNotification", postJson); return(Ok(true)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <Post> AddNewPost(NewPostRequestDto newPost, int userId) { var postToAdd = _mapper.Map <Post>(newPost); postToAdd.PostOwnerId = userId; await _unitOfWork.Posts.AddAsync(postToAdd); await _unitOfWork.CommitAsync(); return(postToAdd); }