/*
         * this method saves a game
         */
        public bool Save(GameStorageModel storageModel)
        {
            // assume the game will not be saved
            bool success = false;

            // databse connection string
            String connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MinesweeperDatabase;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

            // connect to databse in business service to support ACID transactions
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                // instantiate DAO
                GameDAO dao = new GameDAO(connection);

                // open databse connection
                connection.Open();

                // pass control to DAO to delete user previous save
                dao.Delete(storageModel.User);

                // pass control to DAO to save the current game and catch return value
                success = dao.Create(storageModel);

                // close database connection
                connection.Close();
            }

            // return result of save attempt
            return(success);
        }
Esempio n. 2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var confirmResult = MessageBox.Show("Are you sure to delete this item ??",
                                                "Confirm Delete!!",
                                                MessageBoxButtons.OKCancel);

            if (confirmResult == DialogResult.OK)
            {
                if (gDao.Delete(this.curGame.gameID) == false)
                {
                    MessageBox.Show("Cannot found or delete fail!!");
                }
                else
                {
                    MessageBox.Show("Delete successfully");
                }
            }
            ToShowForm();
        }
Esempio n. 3
0
        public void DeleteGame_Success()
        {
            //arrange
            //----make a game model
            Game gameModel = new Game()
            {
                GameState = GameState.Abandoned
            };
            //----make gameDAO
            GameDAO gameDAO = new GameDAO();
            //----make game to be deleted
            Game gameToBeDeleted = gameDAO.Create(gameModel);
            //act
            int?result = gameDAO.Delete(gameToBeDeleted.GameId);

            //assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Value);
        }
Esempio n. 4
0
        public void CreateGame_Success()
        {
            //arrange
            //----make a game model
            Game gameModel = new Game()
            {
                GameState = GameState.Abandoned
            };
            //----make gameDAO
            GameDAO gameDAO = new GameDAO();
            //act
            Game result = gameDAO.Create(gameModel);

            //assert
            Assert.IsNotNull(result);
            Assert.AreEqual(gameModel.GameId, result.GameId);
            Assert.AreEqual(gameModel.GameState, result.GameState);
            //clean up
            gameDAO.Delete(result.GameId);
        }
Esempio n. 5
0
        public void FindGame_Success()
        {
            //arrange
            //----make a game model
            Game gameModel = new Game()
            {
                GameState = GameState.Abandoned
            };
            //----make gameDAO
            GameDAO gameDAO = new GameDAO();
            //----create game from gameModel and save as gameToBeFound
            Game gameToBeFound = gameDAO.Create(gameModel);
            //act
            Game foundGame = gameDAO.Find(gameToBeFound.GameId);

            //assert
            Assert.AreEqual(gameToBeFound.GameId, foundGame.GameId);
            Assert.AreEqual(gameToBeFound.GameState, foundGame.GameState);
            //clean up
            gameDAO.Delete(foundGame.GameId);
        }
Esempio n. 6
0
        public void UpdateGame_Success()
        {
            //arrange
            //----make a game model
            Game gameModel = new Game()
            {
                GameState = GameState.Abandoned
            };
            //----make gameDAO
            GameDAO gameDAO = new GameDAO();
            //----create game from gameModel and save as gameToBeFound
            Game gameToBeUpdated = gameDAO.Create(gameModel);

            //----update gameModel to be reused to update updatedGame
            gameModel.GameState = GameState.Draw;
            //act
            Game updatedGame = gameDAO.Update(gameModel);

            //assert
            Assert.AreEqual(gameModel.GameId, updatedGame.GameId);
            Assert.AreEqual(gameModel.GameState, updatedGame.GameState);
            //clean up
            gameDAO.Delete(updatedGame.GameId);
        }
Esempio n. 7
0
 public void Delete(long id)
 {
     gameDAO.Delete(id);
 }