예제 #1
0
        public ActionResult Search(string Search)
        {
            using (ForumRespository db = new ForumRespository())
            {
                Forum_User CurrentUser = GetCurrentUser(db);

                var Model = new SearchResultsViewModel() { SearchString = Search };

                Model.AddNavigation("Search Results");

                if (!db.CheckRolePermissions(CurrentUser, R => R.AllowSearch))
                    return AuthenticationHelper.AccessDeniedView(Model);

                var Posts = db.GetMatchingPosts(Search);
                var Threads = db.GetMatchingThreads(Search);

                Model.ResultCount = Posts.Count() + Threads.Count();

                // Temp
                int I = 0;
                ThreadInfoModelFromThread(db, CurrentUser, Threads.Take(THREADS_PER_PAGE), Model.ThreadInfoList);
                foreach (var Post in Posts.Take(POSTS_PER_PAGE))
                {
                    Model.PostInfoList.Add(new PostWithThread()
                    {
                        ThreadName = Post.Forum_Thread.Title,
                        Post = new PostViewModel()
                            {
                                Locked = true,
                                PostID = Post.PostID,
                                PostNumber = ++I,
                                PostText = PostParser.Parse(Post.PostText),
                                PostTime = Post.TimeStamp,
                                ThreadID = Post.ThreadID,
                                Poster = new UserViewModel()
                                {
                                    Name = Post.Forum_User.Username,
                                    UserID = Post.Forum_User.UserID
                                }
                            }
                    });
                }

                return View("SearchResults", Model);
            }
        }