/* * this method loads a user's saved game */ public GameStorageModel Load(string user) { // database conection string String connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MinesweeperDatabase;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; // prepare list of storage models to hold DAO method return value List <GameStorageModel> results = new List <GameStorageModel>(); // connect to database in business service // this design supports ACID transactions and is a best practice using (SqlConnection connection = new SqlConnection(connectionString)) { // instantiate DAO GameDAO dao = new GameDAO(connection); // open connection to database connection.Open(); // pass control to DAO to read the user's saved game and catch return value with list results = dao.Read(user); // close databse connection connection.Close(); // if the save wasn't found if (results.Count != 1) { return(null); } // othwerwise return the loaded game else { // transform list to array to acces the game return(results.ToArray()[0]); } } }