Example #1
0
        public TopicViewModel ViewTopic(int topicId)
        {
            var topic = _topicRepo.All()
                        .Where(t => t.Id == topicId)
                        .Include(t => t.CreatedByUser)
                        .ThenInclude(u => u.AvatarFile)
                        .SingleOrDefault();

            if (topic == null)
            {
                return(null);
            }

            var replies = _replyRepo.All()
                          .Where(c => c.TopicId == topicId)
                          .OrderBy(c => c.CreatedAtUtc)
                          .Include(r => r.CreatedByUser)
                          .ThenInclude(u => u.AvatarFile)
                          .Include(r => r.CreatedByWeChatAccount)
                          .ToList();

            // todo:   _eventBus.Publish(new TopicViewedEvent{ TopicId = topicId });
            topic.ViewCount += 1;
            _topicRepo.Update(topic);

            return(TopicViewModel.CreateFrom(topic, replies));
        }
        public ActionResult Index(int id)
        {
            var topic = _topicRepo.All()
                        .Where(t => t.Id == id)
                        .Include(t => t.Author)
                        .SingleOrDefault();

            if (topic == null)
            {
                return(NotFound());
            }

            var replies = _replyRepo.All()
                          .Where(c => c.TopicId == id)
                          .OrderBy(c => c.CreatedAtUtc)
                          .Include(r => r.Author)
                          .ToList();
            var showModel = TopicViewModel.CreateFrom(topic, replies);

            topic.ViewCount++;
            _topicRepo.Update(topic);
            return(View(showModel));
        }