/// <summary>
        /// Refresh universe data
        /// </summary>
        /// <param name="id"></param>
        public async Task <IActionResult> UpdateUniverse(int id)
        {
            var playerList   = OgameApi.GetAllPlayers(id);
            var allianceList = OgameApi.GetAllAlliances(id);
            var planetList   = OgameApi.GetAllPlanets(id);

            var universe = await StarMapBLL.GetServer(id);

            if (universe == null)
            {
                return(NotFound());                  //Server not found
            }
            //Load Alliance
            universe.Alliances          = allianceList.Alliances;
            universe.AllianceLastUpdate = allianceList.LastUpdate;

            //Load Players
            universe.Players           = playerList.Players;
            universe.PlayersLastUpdate = playerList.LastUpdate;

            //Load Planets
            foreach (var planet in planetList.Planets)
            {
                var owner = universe.Players.FirstOrDefault(p => p.Id == planet.OwnerId);
                if (owner == null)
                {
                    continue;                //Ignore if owner not in player list
                }
                var playerPlanet = owner.Planets.FirstOrDefault(pn => pn.Id == planet.Id);
                if (playerPlanet == null)
                {
                    //Add if not exist
                    owner.Planets.Add(planet);
                }
                else
                {
                    //Update if found
                    playerPlanet.Update(planet);
                }
            }
            universe.PlanetsLastUpdate = planetList.LastUpdate;

            //Update statistic
            universe.Statistic.PlayerCount       = universe.Players.Count;
            universe.Statistic.ActivePlayerCount = universe.Players.Where(p => p.IsActive).Count();
            universe.Statistic.PlanetCount       = planetList.Planets.Count;
            universe.Statistic.MoonCount         = planetList.Planets.Where(p => p.Moon != null).Count();
            universe.Statistic.LastUpdate        = DateTimeHelper.GetLatestDate(new List <DateTime>
            {
                planetList.LastUpdate,
                allianceList.LastUpdate,
                planetList.LastUpdate
            });
            universe.Statistic.MapUpdateDay = planetList.LastUpdate.ToString("ddd");
            await StarMapBLL.UpdateServerAsync(universe);

            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// Update the server list
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> UpdateServerList()
        {
            var servers = OgameApi.GetAllUniverses();

            foreach (var server in servers)
            {
                await StarMapBLL.CreateUniverseIfNotExistsAsync(server);
            }
            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// Update player scores
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> UpdateScoreBoard(int id)
        {
            var totalScoreData    = OgameApi.GetHighScore(id, ScoreCategory.Player, ScoreType.Total);
            var econScoreData     = OgameApi.GetHighScore(id, ScoreCategory.Player, ScoreType.Economy);
            var researchScoreData = OgameApi.GetHighScore(id, ScoreCategory.Player, ScoreType.Research);
            var militaryScoreData = OgameApi.GetHighScore(id, ScoreCategory.Player, ScoreType.Military);
            var lastUpdate        = DateTimeHelper.GetLatestDate(new List <DateTime>
            {
                totalScoreData.LastUpdate,
                econScoreData.LastUpdate,
                researchScoreData.LastUpdate,
                militaryScoreData.LastUpdate
            });

            var scoreBoard = await StarMapBLL.GetScoreBoardAsync(id, ScoreCategory.Player);

            if (scoreBoard.LastUpdate == lastUpdate)
            {
                return(RedirectToAction("Index"));                                     //Abort if Api not updated
            }
            // Update total
            foreach (var scoreData in totalScoreData.Scores)
            {
                SetScore(scoreBoard, scoreData.Id, scoreData.Value, ScoreType.Total.ToString(), totalScoreData.LastUpdate);
            }
            // Update Economy
            foreach (var scoreData in econScoreData.Scores)
            {
                SetScore(scoreBoard, scoreData.Id, scoreData.Value, ScoreType.Economy.ToString(), econScoreData.LastUpdate);
            }
            // Update Research
            foreach (var scoreData in researchScoreData.Scores)
            {
                SetScore(scoreBoard, scoreData.Id, scoreData.Value, ScoreType.Research.ToString(), researchScoreData.LastUpdate);
            }
            // Update Military
            foreach (var scoreData in militaryScoreData.Scores)
            {
                SetScore(scoreBoard, scoreData.Id, scoreData.Value, ScoreType.Military.ToString(), militaryScoreData.LastUpdate);
                SetScore(scoreBoard, scoreData.Id, scoreData.Ships, "ShipNumber", militaryScoreData.LastUpdate);
            }
            //Calculate Ship score
            foreach (var score in scoreBoard.Scores)
            {
                var shipScore = score.Total - score.Economy - score.Research;
                SetScore(scoreBoard, score.Id, shipScore, "Ship", militaryScoreData.LastUpdate);
            }
            await StarMapBLL.UpdateScoreBoardAsync(scoreBoard);

            return(RedirectToAction("Index"));
        }