Beispiel #1
0
        public ActionResult Index()
        {
            if (Request[GlobalConst.ASmallCakeCookieName] != null)
            {
                return(RedirectToAction("Index", new {}));
            }
            var db = new ZkDataContext();

            var result = new IndexResult()
            {
                Spotlight    = SpotlightHandler.GetRandom(),
                Top10Players =
                    db.Accounts.Where(x => x.SpringBattlePlayers.Any(y => y.SpringBattle.StartTime > DateTime.UtcNow.AddMonths(-1))).OrderByDescending(
                        x => x.Elo1v1).Take(10)
            };

            result.LobbyStats = AuthServiceClient.GetLobbyStats();
            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 && (Global.Account.LastNewsRead == null || (x.Created > Global.Account.LastNewsRead))).
                    OrderByDescending(x => x.Created);

                if (result.Headlines.Any())
                {
                    db.Accounts.Single(x => x.AccountID == Global.AccountID).LastNewsRead = DateTime.UtcNow;
                    db.SubmitChanges();
                }
            }
            else
            {
                result.Headlines = new List <News>();
            }


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

            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.SingleOrDefault(x => x.AccountID == Global.AccountID)
                                                where read == null || t.LastPost > read.LastRead
                                                orderby t.LastPost descending
                                                select new NewThreadEntry {
                    ForumThread = t, WasRead = read != null, WasWritten = read != null && read.LastPosted != null
                }).
                                    Take(10);
            }

            return(View(result));
        }