/// <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)); }
/// <summary> /// Return the user account. /// </summary> /// <param name="Id"></param> /// <returns></returns> public IActionResult UserAccount(string Id) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("SignIn", "Account")); } using (IDbConnection connection = new MySqlConnection(connectionString)) { if (Id == "null" || Id == null) { Id = User.FindFirstValue(ClaimTypes.NameIdentifier); } UserViewModel currUser = AccountControllerHelperMethods.GetUser(Id, connection); UserStatsModel userStats = AccountControllerHelperMethods.GetUserStats(Id, connection); if (currUser == null) { return(RedirectToAction("Error", "Home")); } posts = AccountControllerHelperMethods.GetAllUserPosts(Id, connection); ViewBag.CurrUser = currUser; ViewBag.UserStats = userStats; ViewBag.Posts = posts; } return(View(new ChangeProfileViewModel())); }