public IActionResult Index(GameType type, int id)
        {
            GopGame game = null;

            switch (type)
            {
            case GameType.Solo:
                game = DbContext.SoloGames.Where(g => g.Id == id).FirstOrDefault();
                break;

            case GameType.Multiplayer:
                game = DbContext.MultiplayerGames.Where(g => g.Id == id).FirstOrDefault();
                break;

            default:
                break;
            }

            if (game == null)
            {
                return(NotFound());
            }

            // See if needs a custom altar
            GopAltar customAltar = null;
            string   altarName   = null;

            if (game.Altar >= Utilities.AltarNames.Length)
            {
                customAltar = DbContext.GopAltars.Where(a => a.Id == game.Altar).FirstOrDefault();
                altarName   = customAltar.Name;
            }
            else
            {
                altarName = Utilities.AltarNames[game.Altar];
            }

            return(View(new WatchView
            {
                Type = type,
                Game = game,
                AltarName = altarName,
                CustomAltar = customAltar
            }));
        }
Exemplo n.º 2
0
        public IActionResult Post(GopAltar altar)
        {
            // First, try to find it in the database
            var result        = DbContext.GopAltars.Where(x => x.Grid == altar.Grid && x.Spawns == altar.Spawns).FirstOrDefault();
            var alreadyExists = true;

            if (result == null)
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                alreadyExists = false;
                result        = altar;

                // Find first hole in IDs of table
                var ids = DbContext.GopAltars.Select(x => x.Id).ToList();
                ids.Sort();
                int newId = ids[ids.Count - 1] + 1;
                for (int i = 0; i < ids.Count - 1; i++)
                {
                    if (ids[i + 1] - ids[i] > 1)
                    {
                        newId = ids[i] + 1;
                        break;
                    }
                }

                altar.Id = newId;
                Logger.LogInformation("Saving altar {0}, {1}, {2}, {3}", altar.Id, altar.Name, altar.Grid, altar.Spawns);
                DbContext.GopAltars.Add(altar);
                DbContext.SaveChanges();
            }

            return(new ObjectResult(new { AlreadyExists = alreadyExists, Id = result.Id }));
        }