Пример #1
0
        public ActionResult Guild(int id = -1, int d = -1, int g = -1)
        {
            #region Validation
            if (id == -1)
            {
                return(View("InvalidResource", model: "bossfight"));
            }

            var difficulty = _difficultyRepository.GetDefaultDifficulty();
            if (difficulty == null)
            {
                return(View("InvalidResource", model: "encounter difficulty"));
            }

            if (d != -1)
            {
                var overrideDifficulty = _difficultyRepository.Get(d);
                if (overrideDifficulty != null)
                {
                    difficulty = overrideDifficulty;
                }
            }

            var bossFight = _bossFightRepository.Get(id);
            if (bossFight == null)
            {
                return(View("InvalidResource", model: "bossfight"));
            }

            var guild = _guildRepository.Get(g);
            if (guild == null)
            {
                return(View("InvalidResource", model: "guild"));
            }

            // Privacy
            if (!Request.IsAuthenticated && guild.HideFromRankings)
            {
                return(View("GuildPrivate"));
            }
            if (guild.HideFromRankings)
            {
                bool sameGuild = false;
                // Check we have a valid user
                var user = _authRepository.GetUserAccount(User.Identity.GetUserId());
                if (user == null)
                {
                    HttpContext.GetOwinContext().Authentication.SignOut();
                    return(RedirectToAction("Index", "Home"));
                }

                // Get the characters for this user
                var userCharacters = _authUserCharacterRepository.GetCharacters(user.Email);
                if (userCharacters.Any(c => c.GuildId == guild.Id) || User.IsInRole(UserGroups.Admin))
                {
                    sameGuild = true;
                }

                if (!sameGuild)
                {
                    return(View("GuildPrivate"));
                }
            }

            #endregion

            var model = new GuildRecords()
            {
                GuildName = guild.Name,
                // Fight related
                BossFight  = bossFight,
                Difficulty = difficulty,
                // General, not guild related
                SingleFastestKill = _encounterRepository.GetFastestKills(id, difficulty.Id).FirstOrDefault(), // Fix this later - use the method that only returns one

                // Player-based
                SingleTopAps = _recordsRepository.GetSingleTopAps(id, difficulty.Id),
                SingleTopDps = _recordsRepository.GetSingleTopDps(id, difficulty.Id),
                SingleTopHps = _recordsRepository.GetSingleTopHps(id, difficulty.Id),
                // Guild-based
                SingleTopApsGuild = _recordsRepository.GetSingleTopApsGuild(id, difficulty.Id),
                SingleTopDpsGuild = _recordsRepository.GetSingleTopDpsGuild(id, difficulty.Id),
                SingleTopHpsGuild = _recordsRepository.GetSingleTopHpsGuild(id, difficulty.Id),
                // This guild-related
                GuildHybridXpsOverTimeChart = _recordCharts.GuildHybridXpsOverTime(id, difficulty.Id, g, guild.Name, bossFight.Name),
                GuildDurationOverTimeChart  = _recordCharts.GetEncounterDurationOverTime(id, difficulty.Id, g, guild.Name, bossFight.Name),
                GuildTopDps            = _recordsRepository.GetTopGuildDps(id, g, difficulty.Id),
                GuildTopHps            = _recordsRepository.GetTopGuildHps(id, g, difficulty.Id),
                GuildTopAps            = _recordsRepository.GetTopGuildAps(id, g, difficulty.Id),
                PlayerDpsOverTimeChart = _recordCharts.GuildPlayerXpsOverTime(id, difficulty.Id, guild.Id, guild.Name, bossFight.Name, "DPS", 20),
                PlayerHpsOverTimeChart = _recordCharts.GuildPlayerXpsOverTime(id, difficulty.Id, guild.Id, guild.Name, bossFight.Name, "HPS", 20),
                PlayerApsOverTimeChart = _recordCharts.GuildPlayerXpsOverTime(id, difficulty.Id, guild.Id, guild.Name, bossFight.Name, "APS", 20),
            };

            if (System.IO.File.Exists(Server.MapPath(string.Format("~/Content/images/portrait/{0}.png", bossFight.PortraitFilename))))
            {
                model.LoadImage = true;
            }

            return(View(model));
        }