Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ThreadPostId,message,dateCreatd,ThreadId")] ThreadPost threadPost)
        {
            if (id != threadPost.ThreadPostId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(threadPost);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ThreadPostExists(threadPost.ThreadPostId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["ThreadId"] = new SelectList(_context.Thread, "ThreadId", "ThreadId", threadPost.ThreadId);
            return(View(threadPost));
        }
Пример #2
0
        public ActionResult NewForumPost(string headline, string forumpost, int id)
        {
            using (ApplicationDbContext context = new ApplicationDbContext())
            {
                var newPost = new ThreadPost();
                newPost.DatePosted = DateTime.Now;
                newPost.ForumPost  = forumpost;
                thread             = context.Thread.FirstOrDefault(u => u.Id == id);
                newPost.Thread     = thread;
                var currentUser = User.Identity.GetUserId();
                user             = context.Users.FirstOrDefault(u => u.Id == currentUser);
                newPost.PostedBy = user.UserName;
                context.ThreadPost.Add(newPost);

                if (ModelState.IsValid)
                {
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (var entityValidationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in entityValidationErrors.ValidationErrors)
                            {
                                Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                            }
                        }
                    }
                }

                return(RedirectToRoute("Test", new { Id = id })); // This route is to make sure a user stays on the same page after posting
            }
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("ThreadPostId,message,DateCreated,ForumId")] ThreadPost threadPost)
        {
            if (ModelState.IsValid)
            {
                _context.Add(threadPost);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["ForumId"] = new SelectList(_context.Forum, "ForumId", "ForumMessage", threadPost.ForumId);
            return(View(threadPost));
        }
Пример #4
0
        public async Task <IActionResult> Create(int?id)
        {
            var threadpost = new ThreadPost();

            threadpost.ThreadId = (int)id;

            var thread = await _context.Thread
                         .Where(t => t.ThreadId == threadpost.ThreadId).ToListAsync();

            var user = await GetCurrentUserAsync();

            ViewData["ThreadId"] = new SelectList(_context.Thread, "ThreadId", "ThreadId");
            return(View(threadpost));
        }
Пример #5
0
        public NewPostAndSuggestions GetSuggestionsAfterAccept(string threadId, ThreadPost acceptedPost, string askingUser)
        {
            if (!hasAccessToThread(threadId, askingUser))
            {
                throw new Exception("You have no access to this thread!");
            }


            var thread = threadRepository.Find(threadId);
            var dbId   = ObjectId.GenerateNewId().ToString();

            thread.ThreadPosts.Add(dbId);
            threadRepository.Update(thread);

            var storedThreadPosts        = postsRepository.Querry(p => thread.ThreadPosts.Contains(p.Id)).ToList();
            var acceptedStoredThreadPost = new StoredThreadPost
            {
                Id             = dbId,
                ThreadId       = threadId,
                PostId         = acceptedPost.Id,
                ConnectedPosts = acceptedPost.ConnectedPosts,
                ThreadIndex    = storedThreadPosts.Count() > 0 ? storedThreadPosts.MaxBy(sTP => sTP.ThreadIndex).First().ThreadIndex + 1 : 0
            };

            storedThreadPosts.Add(acceptedStoredThreadPost);
            postsRepository.Create(acceptedStoredThreadPost);

            var recommendedQuestions = elasticSuggestionHelper.GetRecommendedQuestions(storedThreadPosts.OrderByDescending(sTP => sTP.ThreadIndex)
                                                                                       .Select(sTP => sTP.PostId)
                                                                                       .ToList(),
                                                                                       thread.LastSearched,
                                                                                       thread.TagList.ToList());
            var threadQuestions = questionsElasticRepository.GetAllByIds(storedThreadPosts.Select(sTP => sTP.PostId)
                                                                         .Concat(recommendedQuestions.Select(recQ => recQ.Id))
                                                                         .ToList());

            return(new NewPostAndSuggestions
            {
                NewPost = new ThreadPost
                {
                    Id = acceptedStoredThreadPost.Id,
                    ThreadIndex = acceptedStoredThreadPost.ThreadIndex,
                    Title = acceptedPost.Title,
                    Body = acceptedPost.Body,
                    ConnectedPosts = acceptedStoredThreadPost.ConnectedPosts
                },
                Suggestions = elasticSuggestionHelper.ParseQuestionsToThreadPosts(recommendedQuestions, storedThreadPosts.ToList())
            });
        }
Пример #6
0
        public async Task <IActionResult> Create(ThreadPost threadPost)
        {
            ModelState.Remove("User");
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                threadPost.user = user;
                _context.Add(threadPost);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = threadPost.ThreadId }));
            }
            ViewData["ThreadId"] = new SelectList(_context.Thread, "ThreadId", "ThreadId", threadPost.ThreadId);
            return(View(threadPost));
        }
Пример #7
0
        public async Task OnGet(int id, int pageNumber = 0, bool newestPost = false)
        {
            this.ThreadPost = await this.manager.GetThreadPostsAsync(id, pageNumber, newestPost).ConfigureAwait(false);

            foreach (var post in this.ThreadPost.Posts)
            {
                var threadHtml = await this.parser.ParseDocumentAsync(post.PostHtml).ConfigureAwait(false);

                foreach (var image in threadHtml.QuerySelectorAll("img"))
                {
                    image.SetAttribute("src", $"/proxy?file={image.GetAttribute("src")}");
                }

                post.PostHtml = threadHtml.DocumentElement.OuterHtml;
            }
        }
Пример #8
0
        public List <ThreadPost> GetSuggestionsAfterDecline(string threadId, ThreadPost declinedPost, string askingUser)
        {
            if (!hasAccessToThread(threadId, askingUser))
            {
                throw new Exception("You have no access to this thread!");
            }


            var thread               = threadRepository.Find(threadId);
            var storedThreadPosts    = postsRepository.Querry(p => thread.ThreadPosts.Contains(p.Id));
            var recommendedQuestions = elasticSuggestionHelper.GetRecommendedQuestions(storedThreadPosts.OrderByDescending(sTP => sTP.ThreadIndex)
                                                                                       .Select(sTP => sTP.PostId)
                                                                                       .ToList(),
                                                                                       thread.LastSearched,
                                                                                       thread.TagList.ToList());
            var threadQuestions = questionsElasticRepository.GetAllByIds(storedThreadPosts.Select(sTP => sTP.PostId)
                                                                         .Concat(recommendedQuestions.Select(recQ => recQ.Id))
                                                                         .ToList());


            return(elasticSuggestionHelper.ParseQuestionsToThreadPosts(recommendedQuestions, storedThreadPosts.ToList()));
        }
Пример #9
0
        public ActionResult ReplyToPost(string reply, int id)//<---ThreadpostId
        {
            using (ApplicationDbContext context = new ApplicationDbContext())
            {
                ForumReplies replies = new ForumReplies();
                currentThread      = context.ThreadPost.Where(u => u.Id == id).Select(y => y.Thread.Id).FirstOrDefault();
                threadPost         = context.ThreadPost.FirstOrDefault(u => u.Id == id);
                replies.Threadpost = threadPost;
                replies.Reply      = reply;
                replies.PostedDate = DateTime.Now;
                var currentUser = User.Identity.GetUserId();
                user             = context.Users.FirstOrDefault(u => u.Id == currentUser);
                replies.PostedBy = user.UserName;

                if (ModelState.IsValid)
                {
                    context.Replies.Add(replies);
                    context.SaveChanges();
                }

                return(RedirectToRoute("Test", new { Id = currentThread })); //Route to make sure user stays on the same page after posting
            }
        }
Пример #10
0
 public PostDetailViewModel(ThreadPost post)
 {
     this.Data = post;
 }