Пример #1
0
        public game AddGame(game myGame)
        {
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
                myGame.game_id = sqlConnection.Query<int>(@"insert into game (A1, A2, A3, B1, B2 , B3 , C1, C2, C3 ,status , winner)
                                        values(@A1, @A2,@A3,  @B1, @B2, @B3,  @C1, @C2,  @C3,@status, @winner);
                                        SELECT CAST(SCOPE_IDENTITY() AS INT)",
                    new
                    {
                        A1 = myGame.A1,
                        A2 = myGame.A2,
                        A3 = myGame.A3,
                        B1 = myGame.B1,
                        B2 = myGame.B2,
                        B3 = myGame.B3,
                        C1 = myGame.C1,
                        C2 = myGame.C2,
                        C3 = myGame.C3,
                        status = myGame.status,
                        winner = myGame.winner,
                        gameid = myGame.game_id,

                    }).Single();

                sqlConnection.Close();
            }
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
                sqlConnection.Query<int>(@"insert into players (game_id,user_one_id,user_two_id)
                                                            values(@gameid,@userOneId,@userTwoId);",
                    new
                    {
                        gameid = myGame.game_id,
                        userOneId = myGame.user_one_id,
                        userTwoId = myGame.user_two_id
                    }).Single();

                sqlConnection.Close();
            }
            return myGame;
        }
Пример #2
0
        public void UpdateGame(game myGame)
        {
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
                sqlConnection.Execute(@"update game set
                                        A1 = @A1, A2 = @A2, A3 = @A3,
                                        B1 = @B1, B2 = @B2, B3 = @B3,
                                        C1 = @C1, C2 = @C2, C3 = @C3,
                                        status = @status, winner = @winner
                                        where game_id = @gameid",
                    new
                    {
                          A1= myGame.A1,
                          A2 = myGame.A2,
                          A3 = myGame.A3,
                          B1 = myGame.B1,
                          B2 = myGame.B2,
                          B3 = myGame.B3,
                          C1 = myGame.C1,
                          C2 = myGame.C2,
                          C3 = myGame.C3,
                          status= myGame.status,
                          winner = myGame.winner,
                          gameid = myGame.game_id
                          });
                sqlConnection.Close();

            }
        }