public async Task <IActionResult> Index(string Username) { var user = await _userManager.FindByNameAsync(Username); if (user == null) { throw new ApplicationException("User not found"); } var currentUser = await _userManager.GetUserAsync(User); var UserUser = _socialNetworkDBContext.UserUser.Select(u => new { fd = u.Ppkfkfollowed, fr = u.Ppkfkfollower }); bool?followed = null; if (user != currentUser) { followed = UserUser.Where(u => u.fd == currentUser.Id && u.fr == user.Id).FirstOrDefault() == null ? false : true; } return(View(new ProfileViewModel { Username = user.UserName, Name = user.Name, Surname = user.Surname, Propic = user.AvatarImage, IsFollowed = followed, Followers = _userManager.FindAllFollowers(user, _socialNetworkDBContext), Followed = _userManager.FindAllFollowed(user, _socialNetworkDBContext), Posts = _socialNetworkDBContext.GetAllPosts(user) })); }
public async Task <IActionResult> Profile() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user '{user.UserName}'."); } return(View(new ProfileViewModel { Username = user.UserName, Name = user.Name, Surname = user.Surname, Propic = user.AvatarImage, Posts = _socialNetworkDBContext.GetAllPosts(user) })); }