コード例 #1
0
        public ActionResult Create(DTOGame currentGame)
        {
            if (ModelState.IsValid)
            {
                db.Games.Add(currentGame.GameRound);
                db.SaveChanges();

                db.Database.ExecuteSqlCommand(
                    "DECLARE @publicIDdb nvarchar(5)" +
                    " DECLARE @publicIDrand nvarchar(5)" +
                    " SET @publicIDrand = ROUND(((9999 - 1000 + 1) * RAND() + 1000), 0)" +
                    " WHILE EXISTS (SELECT PublicId FROM dbo.Games WHERE PublicId = @publicIDrand)" +
                    " BEGIN" +
                    " SET @publicIDrand = ROUND(((9999 - 1000 + 1) * RAND() + 1000), 0)" +
                    " END" +
                    " UPDATE Games SET PublicId = @publicIDrand WHERE ID =" + currentGame.GameRound.ID
                    );



                currentGame.CurrentPlayer.Game_Id = currentGame.GameRound.ID;
                db.Players.Add(currentGame.CurrentPlayer);
                db.SaveChanges();
            }

            return(View());
        }
コード例 #2
0
        public void UpdateGame(DTOGame game)
        {
            var parameters = new List <SqlParameter>();

            parameters.Add(CreateSqlParameter("@GameID", System.Data.SqlDbType.Int, game.ID));
            parameters.Add(CreateSqlParameter("@GameDate", System.Data.SqlDbType.DateTime, game.GameDate));
            parameters.Add(CreateSqlParameter("@Team1ID", System.Data.SqlDbType.Int, game.Team1ID));
            parameters.Add(CreateSqlParameter("@Team2ID", System.Data.SqlDbType.Int, game.Team2ID));
            SQLExecuteCommandParam("UpdateGame", parameters);
        }
コード例 #3
0
 public static Game ConvertType(DTOGame o)
 {
     return(new Game()
     {
         GameDate = o.GameDate,
         Team1ID = o.Team1ID,
         Team2ID = o.Team2ID,
         ID = o.ID,
         SportID = o.SportID,
         LeagueID = o.LeagueID
     });
 }
コード例 #4
0
        public ActionResult Create(DTOGame currentGame)
        {
            if (ModelState.IsValid)
            {
                db.Games.Add(currentGame.GameRound);
                db.SaveChanges();

                currentGame.CurrentPlayer.Game_Id = currentGame.GameRound.ID;
                db.Players.Add(currentGame.CurrentPlayer);
                db.SaveChanges();

                //string publicId = currentGame.GameRound.PublicId;
                DTOGameSession session = new DTOGameSession(currentGame);

                return(View("~/Views/GameSession/index.cshtml", session));
            }
            else
            {
                return(new HttpStatusCodeResult(404));
            }
        }
コード例 #5
0
        public async Task <IActionResult> GetGame([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var game = await _context.Games.Include(g => g.Categories)
                       .FirstOrDefaultAsync(m => m.Id == id);

            DTOGame dTOGame = new DTOGame()
            {
                Titulo = game.Titulo, Price = game.Precio, CategoriesString = game.Categories.Name
            };


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

            return(Ok(dTOGame));
        }