public async Task <IActionResult> Details(long id) { var userId = User.Identity.GetUserId <long>(); var topic = await _topicService.GetTopicByIdAsync(id); if (topic == null) { return(NotFound()); } if (topic.Deleted) { return(NotFound()); } if (topic.Status != TopicStatus.Published) { return(NotFound()); } var model = new TopicDetailsViewModel(); model = await PrepareViewModelAsync(model, topic); await _topicService.IncreaseViewCountAsync(topic); model.ShowEditBar = (User.Identity.IsAuthenticated && topic.UserId == userId); return(View(model)); }
public IActionResult <TopicDetailsViewModel> Details(HttpSession session, string topicTitle) { string topicDecoded = WebUtility.UrlDecode(topicTitle); var topic = this.data.Topics.FindByPredicate(t => t.Title == topicDecoded); var tdvm = new TopicDetailsViewModel() { Title = topic.Title, Author = topic.Author.Username, Content = topic.Content, PostedOn = topic.PublishDate.Value.ToString(), UserLogged = this.signInManager.IsAuthenticated(session) }; foreach (Reply reply in topic.Replies) { ReplyViewModel rvm = new ReplyViewModel() { Author = reply.Author.Username, Content = reply.Content, Date = reply.PublishDate.ToString(), ImgUrl = reply.ImageUrl }; tdvm.ReplyViewModels.Add(rvm); } return(this.View(tdvm)); }
public TopicDetailsViewModel GetTopicDetailsViewModel(string id, int pageNumber, string currentUsername) { // todo move projections to ravendb Topic topic = this.ravenSession.Load <Topic>(id); if (topic.ExcludedUserNames.Any(u => u.Equals(currentUsername, StringComparison.OrdinalIgnoreCase))) { throw new UnauthorizedAccessException($"{currentUsername} is not allowed to access {topic.Title}"); } var viewModel = new TopicDetailsViewModel { ExcludedUsernames = topic.ExcludedUserNames, Id = topic.Id, Title = topic.Title, PageNumber = pageNumber, Posts = topic.PostsInOrder .Skip((pageNumber - 1) * ForumOptions.PostsPerPage) .Take(ForumOptions.PostsPerPage) .Select(post => new PostViewModel(post, topic.IsWiki)) .ToList(), TotalNumberOfPosts = topic.PostCount }; if (topic.Poll != null && topic.Poll.Answers.Any()) { viewModel.Poll = new ShowPollViewModel(topic.Poll, currentUsername); } return(viewModel); }
public ActionResult Details(int id) { var topic = this.topics.GetById(id); var topicViewModel = new TopicDetailsViewModel(topic); return(this.View(topicViewModel)); }
private async Task <TopicDetailsViewModel> PrepareViewModelAsync(TopicDetailsViewModel viewModel, Topic topic) { viewModel = topic.ToTopicDetailsModel(); viewModel.Replies = await LoadReplyListAsync(topic.Id); return(viewModel); }
public async Task <IActionResult> Details(int id) { var model = new TopicDetailsViewModel { Topic = await this.topic.ByTopicIdAsync(id), Replies = await this.replies.ByTopicIdAsync(id) }; if (model.Topic == null || model.Replies == null) { return(NotFound()); } return(View(model)); }
public virtual ActionResult Topic(string id, int topicPage) { TopicDetailsViewModel topicDetailsViewModel = this.forumStorageReader.GetTopicDetailsViewModel(id, topicPage, this.User.Identity.Name); return(this.View(topicDetailsViewModel)); }