public IActionResult Show(UserPostVm userPostVm)//metotları göatericz.Sayfaya olduğu gibi dolucak. { userPostVm.Comments = _commentService.GetByPost(userPostVm.PostDto.Id).ToList(); userPostVm.Posts = _postService.GetPosts().ToList(); // listPost = _postService.GetPosts();//getirip listeyi haazırda bekşletir. return(View(userPostVm)); }
public List <UserPostVm> getbyemailProfile(string email) { var allPosts = new List <UserPostVm>(); //get a list of people being followed by the user var userid = ""; var listOfUsers = _context.ApplicationUser.ToList(); var listOfFollowers = _context.UserFollow.ToList(); foreach (var user in listOfUsers) { user.Id = userid; } var useridOfFollowers = _context.ApplicationUser.Where(uf => uf.Email == email).ToList(); var usersBeingFollowed = _context.UserFollow.Where(uf => uf.FollowingUserId == userid).ToList(); var followers = _context.UserFollow.Where(uf => uf.FollowedUserId == userid).ToList(); //loop through list of people being followed foreach (var uf in usersBeingFollowed) { // gets all posts of all people being followed var posts = _context.Post.Where(u => u.ApplicationUserId == uf.FollowedUserId).ToList(); //go through the posts and get info about the post foreach (var post in posts) { var comment = _context.Comment.Where(ui => ui.PostId == post.PostId).FirstOrDefault(); var userLikes = _context.Like.Where(u => u.PostId == post.PostId).ToList(); var user = _context.ApplicationUser.Where(ui => ui.Id == post.ApplicationUserId).FirstOrDefault(); var artist = _context.ApplicationArtist.Where(ai => ai.Id == post.ApplicationArtistId).FirstOrDefault(); var UserFollowedInfo = new UserPostVm() { UserId = user.Id, ProfileImage = user.ImageUrl, ArtistName = artist.Name, PostId = post.PostId, Media = post.Media, Video = post.Video, Caption = post.caption, DateCreated = post.DateCreated, UserName = user.UserName, ApplicationArtistId = artist.Id, Text = comment.Text }; foreach (var like in userLikes) { var NumberOfLikes = userLikes.Count(); UserFollowedInfo.NumberofLikes = NumberOfLikes; } allPosts.Add(UserFollowedInfo); } } return(allPosts); }