Ejemplo n.º 1
0
        public IActionResult <TopicsDetailsViewModel> Details(HttpSession session, int id)
        {
            TopicsDetailsViewModel tdvm = this.topicsService.GenerateTopicsDetailsViewModel(session, id);

            return(this.View(tdvm));
        }
Ejemplo n.º 2
0
        public TopicsDetailsViewModel GenerateTopicsDetailsViewModel(HttpSession session, int id)
        {
            TopicsDetailsViewModel tdvm = new TopicsDetailsViewModel();
            NavbarViewModel        nvm  = new NavbarViewModel();
            TopicViewModel         tvm  = new TopicViewModel();

            if (this.signInManagerService.IsAuthenticated(session))
            {
                var user = this.signInManagerService.GetAuthenticatedUser(session);

                nvm.LoggedIn  = true;
                nvm.UserId    = user.Id;
                nvm.Username  = user.Username;
                nvm.UserLevel = (int)user.Role;
            }
            else
            {
                nvm.LoggedIn = false;
            }

            tdvm.Navbar = nvm;

            var topic = this.Context.Topics.Where(tid => tid.Id == id).FirstOrDefault();

            // Generate tvm
            UserViewModel uvm = new UserViewModel()
            {
                Username = topic.Author.Username,
                UserId   = topic.Author.Id
            };

            tvm.Author = uvm;

            CategoryViewModel cvm = new CategoryViewModel()
            {
                CategoryName = topic.Category.Name,
                CategoryId   = topic.Category.Id
            };

            tvm.Category = cvm;

            tvm.PublishedOn = topic.PublishDate;

            tvm.TopicId = topic.Id;

            tvm.TopicName = topic.Title;

            tvm.Content = topic.Content;

            List <ReplyViewModel> lrvm = new List <ReplyViewModel>();

            foreach (var reply in topic.Replies)
            {
                ReplyViewModel rvm = new ReplyViewModel();

                UserViewModel replyUserViewModel = new UserViewModel()
                {
                    Username = reply.Author.Username,
                    UserId   = reply.Author.Id
                };

                rvm.Content     = reply.Content;
                rvm.User        = replyUserViewModel;
                rvm.PublishedOn = reply.PublishDate;
                rvm.ImgUrl      = reply.ImgUrl;

                lrvm.Add(rvm);
            }

            tvm.Replies = lrvm;

            tdvm.Topic = tvm;

            return(tdvm);
        }