public async Task <ActionResult> Details(string id) { var userId = id ?? string.Empty; // Don't try load a profile called /profile/ if (id.ToLower() == "profile" && Request.IsAuthenticated && User.Identity.Name != "profile") { userId = string.Empty; } // No user ID provided, show user's profile if currently logged in if (string.IsNullOrEmpty(userId) && Request.IsAuthenticated) { var loggedInUser = await _userService.GetByUsername(User.Identity.Name, _ctx); userId = loggedInUser.Id; } // Find profile details var user = await _userService.GetByUsernameOrId(userId, _ctx); if (user == null) { return(Redirect("~/")); } var model = new ProfileViewModel { User = user, PostCount = user.Posts != null && user.Posts.Any() ? user.Posts.Count : 0, FollowerCount = await _followService.FollowerCount(user.UserName, _ctx), FollowingCount = await _followService.FollowingCount(user.UserName, _ctx), Following = false, OwnProfile = false }; if (Request.IsAuthenticated) { model.Following = await _followService.IsFollowing(User.Identity.Name, user.UserName, _ctx); model.OwnProfile = user.UserName == User.Identity.Name; } return(View(model)); }