public ActionResult ViewProfile(int userProfileId) { try { var currentProfile = _profileManager.GetByUserId(User.Identity.GetUserId()); if (userProfileId == currentProfile.Id) { return(RedirectToAction("MyProfile")); } var userProfileViewModel = new UserProfileViewModel(); userProfileViewModel.UserProfile = _profileManager.GetById(userProfileId); userProfileViewModel.Friends = _friendProfileManager.GetAll(userProfileViewModel.UserProfile.Id); ViewBag.UserProfileId = userProfileId; ViewBag.FriendUserProfileId = currentProfile.Id; ViewBag.IsFriend = _friendRequestManager.AreFriends(User.Identity.GetUserId(), userProfileViewModel.UserProfile.UserId); ViewBag.PendingFriend = _friendRequestManager.Exists(User.Identity.GetUserId(), userProfileViewModel.UserProfile.UserId); userProfileViewModel.Friends = _friendProfileManager.GetAll(userProfileViewModel.UserProfile.Id); userProfileViewModel.ProfilePosts = _profilePostManager.GetAll(userProfileViewModel.UserProfile.Id); return(View("Profile", userProfileViewModel)); } catch (Exception e) { return(RedirectToAction("Index", "ErrorHandler", new { @message = e.Message })); } }
public ActionResult ViewProfile(long profileId) { try { var currentProfile = _profileManager.GetByUserId(User.Identity.GetUserId()); if (profileId == currentProfile.Id) { return(RedirectToAction("MyProfile")); } var profileViewModel = new ProfileViewModel(); profileViewModel.Profile = _profileManager.GetById(profileId); //Get current profile profileViewModel.Friends = _friendProfileManager.GetAll(profileViewModel.Profile.Id); //Get all friends by profile ViewBag.ProfileId = profileId; ViewBag.FriendProfileId = currentProfile.Id; ViewBag.IsFriend = _friendRequestManager.AreFriends(User.Identity.GetUserId(), profileViewModel.Profile.UserId); //Two profiles are friend. ViewBag.PendingFriend = _friendRequestManager.Exists(User.Identity.GetUserId(), profileViewModel.Profile.UserId); //is a pending Friend request profileViewModel.Friends = _friendProfileManager.GetAllFavourites(profileViewModel.Profile.Id); //Get all favourite friends by profile. profileViewModel.Posts = _profilePostManager.GetAll(profileViewModel.Profile.Id); //Get all post by profile if (profileId != currentProfile.Id) //If logged users is diferrent a user's profile then add a visitor as visitant { _visitorProfileManager.Add(new VisitorProfile() //If logged user is diferrent a visited user's profile then add a logged user as visitor { ProfileId = profileId, FriendProfileId = currentProfile.Id, Date = DateTime.Now }); } return(View("Profile", profileViewModel)); } catch (Exception e) { return(RedirectToAction("Index", "ErrorHandler", new { @message = e.Message })); } }
public void AddFriend(string userId) { var friendRequestManager = new FriendRequestManager(); var profileManager = new ProfileManager(); var currentUserId = User.Identity.GetUserId(); var currentProfile = profileManager.GetByUserId(currentUserId); var friendProfile = profileManager.GetByUserId(userId); var areFriend = friendRequestManager.AreFriends(currentUserId, userId); if (!areFriend) { var friend = new FriendRequest { UserId = currentUserId, UserProfileId = currentProfile.Id, FriendUserId = userId, FriendUserProfileId = friendProfile.Id, IsFriend = false, }; friendRequestManager.Add(friend); } }