//Skapar en viewmodel för visning av profilsidan private ProfileViewModel GetProfileViewModel(string userId) { var profileCtx = new ProfileDbContext(); var friendCtx = new FriendsDbContext(); var postCtx = new PostDbContext(); var ImgCtx = new ImageDbContext(); var image = ImgCtx.Images.FirstOrDefault(u => u.UserID == userId); var profile = profileCtx.Profiles.FirstOrDefault(p => p.UserId == userId); if (profile.Interests == null) { profile.Interests = new HashSet <string>(); } var posts = postCtx.Posts.Where(po => po.UserId == userId).ToList(); var friends = friendCtx.Friends.Where(f => f.UserID == userId).ToList(); var friendList = new List <FriendViewModel>(); if (friends != null) { foreach (var f in friends) { var friendProfile = profileCtx.Profiles.SingleOrDefault(p => p.UserId == f.FriendUserId); friendList.Add(FriendViewModel.FromProfile(friendProfile)); } } return(new ProfileViewModel() { Profile = profile, Friends = friendList, Posts = posts, Image = image }); }
public ActionResult _FriendRequestPartial() { var uId = User.Identity.GetUserId(); var fRequests = new FriendRequestDbContext(). Requests.Where(u => u.RecieverId == uId).ToList(); var frqSenderIds = fRequests.Select(f => f.SenderId).ToList(); var fProfiles = new ProfileDbContext().Profiles.Where(p => frqSenderIds.Contains(p.UserId)).ToList(); /* var fProfiles = new ProfileDbContext().Profiles.Where(p => * (fRequests.Select(f => f.SenderId).Contains(p.UserId))).ToList();*/ var fReqList = new List <FriendViewModel>(); foreach (var p in fProfiles) { fReqList.Add(FriendViewModel.FromProfile(p)); } return(PartialView("_FriendRequestPartial", fReqList)); }