Ejemplo n.º 1
0
        public ActionResult Delete(int id, GamingModel _gamer)
        {
            try
            {
                //Create instance of DAL, and pass connection string by calling ConnectionString property
                using (GamingCenterDirectoryDB db = new GamingCenterDirectoryDB(ConnectionString))
                {
                    //Call DAL to delete gamer from database
                    db.DeleteGamer(id);
                } // end using

                //Return a 302 redirect action to Index page
                return(RedirectToAction("Index"));
            } // end try
            catch (KeyNotFoundException) // gamer _id was bad
            {
                //Return 404 - Not found status code
                return(new HttpStatusCodeResult(
                           HttpStatusCode.NotFound,
                           string.Format("Gamer with id={0} unknown", id)));
            } // end catch
            catch
            {
                //Return a HttpStatusCodeResult object, and set status code as 500 (InternalServerError) and pass string to print
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Internal Server Error "));
            } // end catch
        }     // end method POST Delete()
Ejemplo n.º 2
0
        [TestMethod] // TestMethod attribute
        public void DeleteGamer()
        {
            //Call ConfigMgr to get connection string, and save it
            string connectionString =
                ConfigurationManager.ConnectionStrings["GamingCenterDBConnectionString"].ConnectionString;

            //Create new GCDB object using connString, and open connection
            using (GamingCenterDirectoryDB db = new GamingCenterDirectoryDB(connectionString))
            {
                //Create new GamingCenter object and initialize given values
                GamingCenter gamer = new GamingCenter()
                {
                    Id           = -1, // database will re-populate id
                    FirstName    = "Ender",
                    LastName     = "Gameless",
                    UserID       = "1111111",
                    GameType     = GameType.Pong,
                    ItemType     = ItemType.PongSet,
                    IsUVUStudent = false,
                    Date         = new DateTime(2009, 4, 11)
                }; // end constructor

                //Create gamer entry
                db.CreateGamer(gamer);

                //Verify Id is NOT negative
                Assert.IsTrue(gamer.Id > 0);

                //Delete the entry
                db.DeleteGamer(gamer.Id);

                //Get the recently deleted gamer
                GamingCenter gamerOld = db.ReadGamer(gamer.Id);

                //Verify the entry is null
                Assert.IsTrue(gamerOld == null);
            } // end using
        }     // end method DeleteGamer()