public async Task <ActionResult <FollowingResponse> > Follow(string username) { _logger.LogInformation("Received profile follow request."); _logger.LogInformation("Profile username: {0}", username); User currentUser = _currentUserService.GetCurrentUser(HttpContext); _logger.LogInformation("Requesting user email: {0}", currentUser.Email); try { Follow newFollow = await _followService.FollowUser(username, currentUser.Email); newFollow.Follower = currentUser; // Publish event. _logger.LogInformation("Publishing follow notification."); await _notificationService.Publish(new FollowNotification(_mapper.Map <FollowResponse>(newFollow))); _logger.LogInformation("Successfully followed '{0}' for '{1}'.", username, currentUser.Email); return(Ok(_mapper.Map <FollowingResponse>(newFollow))); } catch (EntityNotFoundException <string> ) { _logger.LogError("Profile with username '{0}' does not exist.", username); return(NotFound()); } catch (OwnProfileFollowException) { _logger.LogError("User '{0}' cannot follow their own profile '{1}'.", currentUser.Email, username); return(BadRequest()); } }
public async Task <IActionResult> Follow(Guid FollowerId, Guid UserId) { if (FollowerId != null && UserId != null) { var result = await followService.FollowUser(FollowerId, UserId); if (result != null) { return(Ok(new { message = "You're now following the user" })); } } return(BadRequest(new { message = "Values cannot be null" })); }
public async Task <ApiResult> PostFollower(FollowMessage message) { try { var followerId = User.Claims.First(c => c.Type == ClaimTypes.Name).Value.ToString(); var result = await _followService.FollowUser(followerId, message.Id); return(result ? ApiResult.Success("Followed successfully") : ApiResult.BadRequest("Something went wrong")); } catch (System.Exception) { return(ApiResult.BadRequest("Something went wrong")); } }
private async Task <bool> AutoFollow(Guid memberId) { //first we get the leadpastor by email var pastor = userManager.FindByEmailAsync("*****@*****.**").Result; if (pastor != null) { var follwership = await followService.FollowUser(memberId, Guid.Parse(pastor.Id)); if (follwership != null) { return(true); } } return(false); }
public void FollowService_Create() { var result = service.FollowUser(2, 1); Assert.IsTrue(result > 0); }