コード例 #1
0
        // GET: Topics/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Topic topic = await _context.Topic
                          .Include(t => t.TopicCategory)
                          .Include(t => t.User)
                          .ThenInclude(u => u.House)
                          .Include(t => t.Comments)
                          .ThenInclude(c => c.User)
                          .ThenInclude(u => u.House)
                          .FirstOrDefaultAsync(m => m.TopicId == id);

            topic.Comments = topic.Comments.OrderByDescending(c => c.DateCreated).ToList();

            ApplicationUser user = await GetCurrentUserAsync();

            House house = await _context.House.SingleOrDefaultAsync(h => h.HouseId == user.HouseId);

            user.House = house;

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

            if (topic.HouseExclusive == true && topic.User.HouseId != user.HouseId)
            {
                return(RedirectToAction("ViewGreatHall", "Home"));
            }

            DetailsTopicViewModel viewmodel = new DetailsTopicViewModel();

            viewmodel.Edit = true;

            if (topic.UserId != user.Id)
            {
                topic.TotalViews++;
                viewmodel.Edit = false;
            }

            viewmodel.Topic = topic;
            viewmodel.User  = user;

            _context.Update(topic);
            await _context.SaveChangesAsync();

            ViewData["scripts"] = new List <string>()
            {
                "HandleComments"
            };

            return(View(viewmodel));
        }
コード例 #2
0
        public async Task <IActionResult> Details(int id)
        {
            var topic = await _service.GetTopicAsync(id);

            var viewModel = new DetailsTopicViewModel
            {
                Title          = topic.Title,
                Content        = topic.Content,
                AuthorUserName = topic.Author.UserName,
                CreatedOn      = topic.CreatedOn,
                Posts          = topic.Posts.ToList()
            };

            return(View(viewModel));
        }
コード例 #3
0
ファイル: TopicsService.cs プロジェクト: Ivolekov/SoftUni_3.0
        public DetailsViewModel GetDetailsViewModel(int id)
        {
            Topic topic = this.Context.Topics.Find(id);
            DetailsTopicViewModel topicViewModel = new DetailsTopicViewModel()
            {
                Title       = topic.Title,
                AuthorName  = topic.Author.Username,
                Content     = topic.Content,
                PublishDate = topic.PublishedDate
            };
            IEnumerable <DetailsReplyViewModel> reply = topic.Replies.Select(r => new DetailsReplyViewModel
            {
                AuthorName  = r.Author.Username,
                Content     = r.Content,
                ImageUrl    = r.ImageUrl,
                PublishDate = r.PublishedDate
            });

            return(new DetailsViewModel
            {
                Topic = topicViewModel,
                Replies = reply
            });
        }