public async Task <IActionResult> AcceptFriend(InFriendViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = userService.GetCurrentUserId(HttpContext); var response = await friendshipService.AcceptFriend(userId, viewModel.FriendID).ConfigureAwait(false); if (!response.IsSuccess) { return(BadRequest(response.Message)); } var(requestedFriends, receivedFriends) = await friendshipService.GetUserFriends(userId).ConfigureAwait(false); var requestedFriendsViewModel = mapper.Map <IEnumerable <(User, FriendshipStatus)>, IEnumerable <OutFriendViewModel> >(requestedFriends); var receivedFriendsViewModel = mapper.Map <IEnumerable <(User, FriendshipStatus)>, IEnumerable <OutFriendViewModel> >(receivedFriends); return(Ok(new { requestedFriends = requestedFriendsViewModel, receivedFriends = receivedFriendsViewModel }));//TODO: signalr }
public async Task <IActionResult> RequestFriend(InFriendViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = userService.GetCurrentUserId(HttpContext); var friendship = new Friendship() { SrcUserID = userId, DestUserID = viewModel.FriendID, Status = FriendshipStatus.Pending }; var response = await friendshipService.Create(friendship).ConfigureAwait(false); if (!response.IsSuccess) { return(BadRequest(response.Message)); } var(requestedFriends, receivedFriends) = await friendshipService.GetUserFriends(userId).ConfigureAwait(false); var requestedFriendsViewModel = mapper.Map <IEnumerable <(User, FriendshipStatus)>, IEnumerable <OutFriendViewModel> >(requestedFriends); var receivedFriendsViewModel = mapper.Map <IEnumerable <(User, FriendshipStatus)>, IEnumerable <OutFriendViewModel> >(receivedFriends); return(Ok(new { requestedFriends = requestedFriendsViewModel, receivedFriends = receivedFriendsViewModel }));//TODO: signalr czy coś do zapraszanego }