// GET: MyPosts/Details/5 public ActionResult Details(int id) { var post = _postRepo.GetPublishedPostById(id); if (post == null) { int userId = GetCurrentUserProfileId(); post = _postRepo.GetUserPostById(id, userId); if (post == null) { return(NotFound()); } } post.Tags = _postTagRepo.GetPostTags(id); return(RedirectToAction("Details", "Post", new { id = id })); }
// GET: PostTagController public ActionResult Manage(int id) { var vm = new PostTagViewModel(); var post = _postRepo.GetPostById(id); vm.Post = post; if (post == null) { return(RedirectToAction("Index", "MyPosts")); } int currentUserId = GetCurrentUserProfileId(); string UsersRole = GetCurrentUserRole(); if (UsersRole == "Author" && post.UserProfileId != currentUserId) { return(RedirectToAction("Index", "MyPosts")); } List <Tag> postTags = _postTagRepo.GetPostTags(id); //list of all tags for this particular post vm.Tags = postTags; //create a comma separated string of the tags if (postTags.Count > 0) { string tagString = ""; for (int i = 0; i < postTags.Count; i++) { tagString += postTags[i].Name; if (i != (postTags.Count - 1)) { tagString += ","; } } vm.TagString = tagString; } vm.TagList = _tagRepo.GetAll(); //list of all possible tags return(View(vm)); }
public IActionResult Details(int id) { var post = _postRepository.GetPublishedPostById(id); int userId = GetCurrentUserProfileId(); if (post == null) { post = _postRepository.GetUserPostById(id, userId); if (post == null) { return(NotFound()); } } post.Tags = _postTagRepo.GetPostTags(id); post.IsSubscribed = _subRepo.IsSubscribed(new SubscribeViewModel() { SubscriberUserId = userId, ProviderUserId = post.UserProfileId }); var vm = new PostIndexViewModel(); vm.PostModel = post; vm.UserId = GetCurrentUserProfileId(); return(View(vm)); }
public IActionResult Index() { int?currentUserId = GetCurrentUserProfileId(); if (currentUserId == null) { return(View()); } else { List <Post> posts = _postRepo.GetSubscribedPostByUserId(currentUserId); foreach (Post post in posts) { List <Tag> tags = _postTagRepo.GetPostTags(post.Id); post.Tags = tags; } HomeViewModel vm = new HomeViewModel() { CurrentUserId = currentUserId, Posts = posts }; return(View(vm)); } }