Ejemplo n.º 1
0
        public ActionResult Index(int? p, string term)
        {
            if (!string.IsNullOrEmpty(term))
            {
                using (UnitOfWorkManager.NewUnitOfWork())
                {
                    // Set the page index
                    var pageIndex = p ?? 1;

                    // Returns the formatted string to search on
                    var formattedSearchTerm = StringUtils.ReturnSearchString(term);

                    // Get lucene to search
                    var luceneResults = _luceneService.Search(formattedSearchTerm, pageIndex, SettingsService.GetSettings().TopicsPerPage);

                    //// Get all the topics based on the search value
                    //var topics = _topicsService.SearchTopics(pageIndex,
                    //                                     SettingsService.GetSettings().TopicsPerPage,
                    //                                     AppConstants.ActiveTopicsListSize,
                    //                                     term);

                    var topics = _topicsService.GetTopicsByCsv(pageIndex, SettingsService.GetSettings().TopicsPerPage, AppConstants.ActiveTopicsListSize, luceneResults.Select(x => x.TopicId).ToList());

                    // Get all the categories for this topic collection
                    var categories = topics.Select(x => x.Category).Distinct();

                    // create the view model
                    var viewModel = new SearchViewModel
                    {
                        Topics = topics,
                        AllPermissionSets = new Dictionary<Category, PermissionSet>(),
                        PageIndex = pageIndex,
                        TotalCount = luceneResults.TotalCount,
                        Term = formattedSearchTerm
                    };

                    // loop through the categories and get the permissions
                    foreach (var category in categories)
                    {
                        var permissionSet = RoleService.GetPermissions(category, UsersRole);
                        viewModel.AllPermissionSets.Add(category, permissionSet);
                    }

                    return View(viewModel);
                }
            }

            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 2
0
        public ActionResult Index(int? p, string term)
        {
            if (!string.IsNullOrEmpty(term))
            {
                using (UnitOfWorkManager.NewUnitOfWork())
                {
                    // Get the global settings
                    var settings = SettingsService.GetSettings();

                    // Get allowed categories
                    var allowedCategories = _categoryService.GetAllowedCategories(UsersRole);

                    // Set the page index
                    var pageIndex = p ?? 1;

                    // Get all the topics based on the search value
                    var posts = _postService.SearchPosts(pageIndex,
                                                         settings.PostsPerPage,
                                                         SiteConstants.SearchListSize,
                                                         term,
                                                         allowedCategories);

                    // Get all the permissions for these topics
                    var topicPermissions = ViewModelMapping.GetPermissionsForTopics(posts.Select(x => x.Topic), RoleService, UsersRole);

                    // Get the post Ids
                    var postIds = posts.Select(x => x.Id).ToList();

                    // Get all votes for these posts
                    var votes = _voteService.GetVotesByPosts(postIds);

                    // Get all favourites for these posts
                    var favs = _favouriteService.GetAllPostFavourites(postIds);

                    // Create the post view models
                    var viewModels = ViewModelMapping.CreatePostViewModels(posts.ToList(), votes, topicPermissions, LoggedOnUser, settings, favs);

                    // create the view model
                    var viewModel = new SearchViewModel
                    {
                        Posts = viewModels,
                        PageIndex = pageIndex,
                        TotalCount = posts.TotalCount,
                        TotalPages = posts.TotalPages,
                        Term = term
                    };

                    return View(viewModel);
                }
            }

            return RedirectToAction("Index", "Home");
        }