// GET: Member/Post public ActionResult Show(int id) { PostDetailsVM data = new PostDetailsVM(); data.Post = _postRepo.GetById(id); data.AppUser = _appUserRepo.GetById(data.Post.AppUserId); data.Comments = _commentRepo.GetDefault(x => x.PostId == id && x.Status != Status.Passived); return(View()); }
public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } Post post = await _db.Posts.FindAsync(id); if (post == null) { return(NotFound()); } User currentUser = await _userManager.GetUserAsync(User); User postOwner = await _userManager.FindByIdAsync(post.UserId); List <User> friends = new List <User>(); foreach (Friend item in _db.Friends.Include(f => f.FriendTo).Include(f => f.FriendFrom).Where(f => f.Accepted)) { if (item.FriendFrom == postOwner) { friends.Add(item.FriendTo); } else if (item.FriendTo == postOwner) { friends.Add(item.FriendFrom); } } bool isFriend = false; foreach (User f in friends) { if (currentUser == f) { isFriend = true; } } if (postOwner.Private && !isFriend && postOwner != currentUser) { return(NotFound()); } PostDetailsVM model = new PostDetailsVM() { User = currentUser, Post = _db.Posts.Include(p => p.User).Include(p => p.PostTaggedUsers).Include(p => p.PostLikes).Include(p => p.PostImages).Include(p => p.SavedPosts).Include(p => p.Comments).FirstOrDefault(p => p.Id == id), PostTaggedUsers = _db.PostTaggedUsers.Include(p => p.User), Comments = _db.Comments.Include(c => c.User).Include(c => c.CommentLikes).Include(c => c.Replies).Where(c => c.PostId == id).OrderByDescending(c => c.CommentLikes.Count()), CurrentUserRole = (await _userManager.GetRolesAsync(currentUser))[0] }; return(View(model)); }
public async Task <IActionResult> Details(int id) { var currentUserName = User.Identity.Name; var currentUser = await _userManager.FindByNameAsync(currentUserName); var posts = _postService.GetYourPosts(currentUser); var post = posts.FirstOrDefault(i => i.Id == id); var postVM = new PostDetailsVM() { PostName = post.PostName, PostId = post.Id, Bids = post.Bids .Where(i => i.IsDone == false && i.Status == Entites.Enums.BidStatus.Waiting).ToList() }; return(View(postVM)); }
public async Task <IActionResult> PostComment(int?id, PostDetailsVM postDetailsVM) { if (string.IsNullOrEmpty(postDetailsVM.Comment.Text.Trim())) { return(BadRequest()); } Post post = await _db.Posts.FindAsync(id); if (post == null) { return(NotFound()); } Comment comment = postDetailsVM.Comment; comment.Date = DateTime.Now; User currentUser = await _userManager.GetUserAsync(User); comment.UserId = currentUser.Id; comment.PostId = (int)id; _db.Comments.Add(comment); if (currentUser.Id != post.UserId) { Notification notification = new Notification() { Date = DateTime.Now, NotificationFromId = currentUser.Id, NotificationToId = post.UserId, PostId = (int)id, NotificationTypeId = 3 }; _db.Notifications.Add(notification); } await _db.SaveChangesAsync(); return(RedirectToAction("Details", "Post", new { id = id })); }