/// <summary> /// Check if current user if following the author of the given post and pass this info into the view. /// </summary> /// <param name="id"></param> /// <param name="postId"></param> /// <returns></returns> public IActionResult GetAuthorGeneralInfo(string id, string postId) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("SignIn", "Account")); } UserViewModel user; using (IDbConnection connection = new MySqlConnection(connectionString)) { user = AccountControllerHelperMethods.GetUser(id, connection); if (User.FindFirstValue(ClaimTypes.NameIdentifier) != id) { bool following = AccountControllerHelperMethods.IsCurrentUserFollowing(connection, User.FindFirstValue(ClaimTypes.NameIdentifier), id); user.Current_User_Following = following; } else { user.Current_User_Following = false; } } ViewBag.PostId = postId; ViewBag.UserId = user.Id; return(PartialView(user)); }
public IActionResult GetFollowers(string id) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("SignIn", "Account")); } List <UserViewModel> followers = new List <UserViewModel>(); using (IDbConnection connection = new MySqlConnection(connectionString)) { followers = AccountControllerHelperMethods.GetAllFollowers(connection, id); for (int i = 0; i < followers.Count; i++) { bool isFollowing = AccountControllerHelperMethods.IsCurrentUserFollowing(connection, User.FindFirstValue(ClaimTypes.NameIdentifier), followers[i].Id); followers[i].Current_User_Following = isFollowing; } } ViewBag.CurrUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); ViewBag.UserProfileId = id; return(PartialView(followers)); }
/// <summary> /// Get all users. /// </summary> /// <returns></returns> public IActionResult GetAllUsers() { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("SignIn", "Account")); } List <UserViewModel> users; using (IDbConnection connection = new MySqlConnection(connectionString)) { users = AccountControllerHelperMethods.GetAllUsers(User.FindFirstValue(ClaimTypes.NameIdentifier), connection); foreach (var user in users) { bool isFollowing = AccountControllerHelperMethods.IsCurrentUserFollowing(connection, User.FindFirstValue(ClaimTypes.NameIdentifier), user.Id); user.Current_User_Following = isFollowing; } } return(View(users)); }