Exemplo n.º 1
0
        /// <summary>
        /// Go to home page; also updates news read dates
        /// </summary>
        public ActionResult Index()
        {
            // TODO: make two separate pages -- one for logged in users, one for not-logged in users
            // logged in users see their user profile
            // non-logged in users see promotional page

            var db = new ZkDataContext();

            if (!Global.IsAccountAuthorized)
            {
                return(View("Splash"));
            }

            // TODO: randomized backgrounds move here
            var result = new IndexResult
            {
                Spotlight         = SpotlightHandler.GetRandom(),
                Top10Players      = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(10),
                WikiRecentChanges = MediaWikiRecentChanges.LoadRecentChanges(),
                LobbyStats        = MemCache.GetCached("lobby_stats", GetCurrentLobbyStats, 60 * 2),
                News       = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created),
                Headlines  = GetHeadlines(db),
                NewThreads = GetNewForumThreads(db)
            };

            return(View("HomeIndex", result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Go to home page; also updates news read dates
        /// </summary>
        public ActionResult Index()
        {
            var db = new ZkDataContext();


            var result = new IndexResult()
            {
                Spotlight         = SpotlightHandler.GetRandom(),
                Top10Players      = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(10),
                WikiRecentChanges = MediaWikiRecentChanges.LoadRecentChanges()
            };

            result.LobbyStats = MemCache.GetCached("lobby_stats", GetCurrentLobbyStats, 60 * 2);

            result.News = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created);
            if (Global.Account != null)
            {
                result.Headlines =
                    db.News.Where(
                        x => x.Created <DateTime.UtcNow && x.HeadlineUntil != null && x.HeadlineUntil> DateTime.UtcNow && !x.ForumThread.ForumThreadLastReads.Any(y => y.AccountID == Global.AccountID && y.LastRead != null)).
                    OrderByDescending(x => x.Created).ToList();

                if (result.Headlines.Any())
                {
                    foreach (var h in result.Headlines)
                    {
                        h.ForumThread.UpdateLastRead(Global.AccountID, false);
                    }

                    db.SaveChanges();
                }
            }
            else
            {
                result.Headlines = new List <News>();
            }


            var accessibleThreads = db.ForumThreads.Where(x => x.RestrictedClanID == null || x.RestrictedClanID == Global.ClanID);

            accessibleThreads = accessibleThreads.Where(x => x.ForumCategory.ForumMode != ForumMode.Archive);
            if (!Global.IsAccountAuthorized)
            {
                result.NewThreads = accessibleThreads.OrderByDescending(x => x.LastPost).Take(10).Select(x => new NewThreadEntry()
                {
                    ForumThread = x
                });
            }
            else
            {
                result.NewThreads = (from t in accessibleThreads
                                     let read = t.ForumThreadLastReads.FirstOrDefault(x => x.AccountID == Global.AccountID)
                                                let readForum = t.ForumCategory.ForumLastReads.FirstOrDefault(x => x.AccountID == Global.AccountID)
                                                                where (read == null || t.LastPost > read.LastRead) && (readForum == null || t.LastPost > readForum.LastRead)
                                                                orderby t.LastPost descending
                                                                select new NewThreadEntry {
                    ForumThread = t, WasRead = read != null, WasWritten = read != null && read.LastPosted != null
                }).
                                    Take(10);
            }



            return(View("HomeIndex", result));
        }