public IActionResult ForumThread(long threadID)
        {
            ViewData["Message"] = "Your contact page.";


            var viewModel = new ForumThreadViewModel();

            viewModel.threadID = threadID;
            try
            {
                viewModel.articlesList = _context.Threads.Include(t => t.Articles).Where(t => t.ThreadID == threadID).FirstOrDefault().Articles.ToList();
            }
            catch (System.Exception)
            {
                List <Article> al = new List <Article>();
                al.Add(new Article
                {
                    Text   = "no Article",
                    Thread = _context.Threads.Find(viewModel.threadID)
                });

                viewModel.articlesList = al;
            }


            return(View(viewModel));
        }
        public IActionResult ForumThread(ForumThreadViewModel viewModel)
        {
            ViewData["Message"] = "Your contact page.";

            var newArticle = new Article();

            newArticle.Text   = viewModel.text;
            newArticle.Thread = _context.Threads.Find(viewModel.threadID);
            newArticle.Time   = DateTime.Now;

            _context.Articles.Add(newArticle);
            _context.SaveChanges();

            var viewModel2 = new ForumThreadViewModel();

            viewModel2.threadID = viewModel.threadID;
            try
            {
                viewModel2.articlesList = _context.Threads.Find(viewModel.threadID).Articles.Where(a => a.Thread.ThreadID == viewModel.threadID).ToList();
            }
            catch (System.Exception)
            {
                List <Article> al = new List <Article>();
                al.Add(new Article
                {
                    Text   = "no Article",
                    Thread = _context.Threads.Find(viewModel.threadID)
                });

                viewModel2.articlesList = al;
            }

            return(View(viewModel2));
        }
Beispiel #3
0
        public IActionResult CreatePost(ForumThreadViewModel forumThreadViewModel)
        {
            forumPost.ThreadID    = forumThreadViewModel.ThreadID;
            forumPost.AccountID   = forumThreadViewModel.PosterAccountID;
            forumPost.PostMessage = forumThreadViewModel.PosterMessage;

            forumPostCollection.CreatePost(forumPost);

            return(RedirectToAction("ThreadPage", "Forum", new { forumThreadViewModel.ThreadID }));
        }
        public async Task <ActionResult> ViewThread(int projectid, int forumThreadId)
        {
            var forumThread = await GetForumThread(projectid, forumThreadId);

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

            var viewModel = new ForumThreadViewModel(forumThread, CurrentUserId);

            return(View(viewModel));
        }
Beispiel #5
0
        public IActionResult ThreadPage(int threadID)
        {
            forumThread = forumThreadCollection.GetForumThread(threadID);
            account     = accountCollection.GetAccount(forumThread.AccountID);
            List <IForumPost> forumPosts = forumPostCollection.GetForumPosts(threadID);

            ForumThreadViewModel model = new ForumThreadViewModel()
            {
                ThreadID          = forumThread.ThreadID,
                ThreadCreator     = account,
                ThreadTitle       = forumThread.ThreadTitle,
                ThreadMessage     = forumThread.ThreadMessage,
                ThreadDateCreated = forumThread.ThreadDateCreated,
                Posts             = forumPosts
            };

            return(View(model));
        }
        //[Test]
        public void ThreadController_Index_ShouldReturnAnswersEqulToPageSizeAndOrederedByPublishedProperyAtPage2()
        {
            // Arrange
            var data             = new Mock <IUowData>();
            var pagerFactory     = new Mock <IPagerViewModelFactory>();
            var viewModelFactory = new Mock <IViewModelFactory>();

            data.Setup(d => d.Threads.All()).Returns(TestThread().AsQueryable());
            data.Setup(d => d.Answers.All()).Returns(AnswersCollection().AsQueryable);

            var controller = new ThreadController(data.Object, pagerFactory.Object, viewModelFactory.Object);

            var expected = new List <Answer>()
            {
                new Answer()
                {
                    Id = 1, IsVisible = true, Published = new DateTime(2017, 01, 04), ThreadId = 1, Content = string.Empty, Comments = new List <Comment>()
                    {
                        new Comment()
                        {
                            Id = 2, IsVisible = false
                        }
                    }
                },
                new Answer()
                {
                    Id = 5, IsVisible = true, Published = new DateTime(2017, 01, 05), ThreadId = 1, Content = string.Empty
                },
                new Answer()
                {
                    Id = 6, IsVisible = true, Published = new DateTime(2017, 01, 06), ThreadId = 1, Content = string.Empty
                }
            };

            // Act
            var result = controller.Index(1, 2) as ViewResult;
            ForumThreadViewModel resultModel = result.Model as ForumThreadViewModel;

            // Assert
            CollectionAssert.AreEqual(expected, resultModel.Answers, new AnswerComparer());
        }
        public async Task <IActionResult> CreateThread(ForumThreadViewModel viewModel)
        {
            var user = await _userManager.GetUserAsync(User);

            var thread = new ForumThread
            {
                IllegalObjectId   = viewModel.IllegalObjectId,
                Theme             = viewModel.Theme,
                Description       = viewModel.Description,
                ApplicationUserId = user.Id,
                CreatedAt         = DateTime.Now
            };

            _context.ForumThreads.Add(thread);
            _context.SaveChanges();

            viewModel.ForumThreadId = thread.ForumThreadId;
            viewModel.LastUpdate    = thread.CreatedAt;

            return(PartialView("_ThreadLite", viewModel));
        }
        public IActionResult Thread(int id)
        {
            var thread = _context.ForumThreads
                         .Include(x => x.Comments)
                         .ThenInclude(x => x.ApplicationUser)
                         .FirstOrDefault(x => x.ForumThreadId == id);

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

            var viewModel = new ForumThreadViewModel
            {
                ForumThreadId   = thread.ForumThreadId,
                IllegalObjectId = thread.IllegalObjectId,
                Description     = thread.Description,
                Theme           = thread.Theme,
                Comments        = thread.Comments
                                  .Select(x => new CommentViewModel
                {
                    CommentId       = x.CommentId,
                    UserId          = x.ApplicationUserId,
                    UserName        = x.ApplicationUser.UserName,
                    Email           = x.ApplicationUser.Email,
                    CommentText     = x.CommentText,
                    ForumThreadId   = x.ForumThreadId,
                    ParentCommentId = x.ParentCommentId,
                    CreatedAt       = x.CreatedAt
                })
                                  .OrderByDescending(x => x.CreatedAt)
                                  .ToList()
            };

            return(View(viewModel));
        }
Beispiel #9
0
 public async Task <IActionResult> AddnewForumThread([FromBody] ForumThreadViewModel model)
 {
     //Do code here
     throw new NotImplementedException();
 }