예제 #1
0
        public ActionResult Index()
        {
            var viewModel = new IndexViewModel
                                {
                                    // 1. All the questions, ordered by most recent.
                                    Questions = DocumentSession.Query<Question>()
                                        .OrderByDescending(x => x.CreatedOn)
                                        .Take(20)
                                        .ToList(),
                                    // 2. All the tags, ordered by most recent.
                                    // TODO: I think this will be a facetted index.

                                    // 3. Log in user information.
                                    //AuthenticationViewModel = AuthenticationViewModel
                                };

            ViewBag.UserDetails = AuthenticationViewModel;

            return View(viewModel);
        }
예제 #2
0
        public ActionResult AggressiveIndex(string displayName)
        {
            using (DocumentSession.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(1)))
            {
                // 1. All the questions, ordered by most recent.
                Lazy<IEnumerable<Question>> questionsQuery = DocumentSession.Query<Question>()
                    .OrderByDescending(x => x.CreatedOn)
                    .Take(20)
                    .Lazily();

                // 2. Popular Tags for a time period.
                // StackOverflow calls it 'recent tags'.
                Lazy<IEnumerable<RecentTags.ReduceResult>> popularTagsThisMonthQuery =
                    DocumentSession.Query<RecentTags.ReduceResult, RecentTags>()
                        .Where(x => x.LastSeen > DateTime.UtcNow.AddMonths(-1).ToUtcToday())
                        .Take(20)
                        .Lazily();

                // 3. Log in user information.
                //AuthenticationViewModel = AuthenticationViewModel
                Lazy<IEnumerable<User>> userQuery = DocumentSession.Query<User>()
                    .Where(x => x.DisplayName == displayName)
                    .Lazily();

                var viewModel = new IndexViewModel
                                    {
                                        Header = "Top Questions",
                                        Questions = questionsQuery.Value.ToList(),
                                        PopularTagsThisMonth = popularTagsThisMonthQuery.Value.ToList(),
                                        UserTags = (userQuery.Value.SingleOrDefault() ?? new User()).FavTags
                                    };

                ViewBag.UserDetails = AuthenticationViewModel;

                return View("Index", viewModel);
            }
        }
예제 #3
0
        public ActionResult Index(string displayName, string tag)
        {
            string header = "Top Questions";

            // 1. All the questions, ordered by most recent.
            IQueryable<Question> questionsQuery = DocumentSession.Query<Question>()
                .OrderByDescending(x => x.CreatedOn)
                .Take(20);

            // Filter by Tags?
            if (!string.IsNullOrEmpty(tag))
            {
                header = "Tagged Questions";
                questionsQuery = questionsQuery
                    .Where(x => x.Tags.Any(y => y == tag));
            }

            // 2. Popular Tags for a time period.
            // StackOverflow calls it 'recent tags'.
            IQueryable<RecentTags.ReduceResult> popularTagsThisMonthQuery =
                DocumentSession.Query<RecentTags.ReduceResult, RecentTags>()
                    .Where(x => x.LastSeen > DateTime.UtcNow.AddMonths(-1).ToUtcToday())
                    .Take(20);

            // 3. Log in user information.
            //AuthenticationViewModel = AuthenticationViewModel
            IRavenQueryable<User> userQuery = DocumentSession.Query<User>()
                .Where(x => x.DisplayName == displayName);

            var viewModel = new IndexViewModel
                                {
                                    Header = header,
                                    Questions = questionsQuery.ToList(),
                                    PopularTagsThisMonth = popularTagsThisMonthQuery.ToList(),
                                    UserTags = (userQuery.SingleOrDefault() ?? new User()).FavTags
                                };

            ViewBag.UserDetails = AuthenticationViewModel;

            return View(viewModel);
        }