protected void btnUpdate_Click(object sender, EventArgs e)
    {
        String  StrDatePublished = calDatePublished.SelectedDate.ToLongDateString();
        clsGame aGame            = new clsGame();
        String  Error            = aGame.Valid(txtGameTitle.Text, txtPrice.Text, txtDiscount.Text, StrDatePublished);

        if (Error == "")
        {
            aGame.GameId        = GameId;
            aGame.GameTitle     = txtGameTitle.Text;
            aGame.Price         = Convert.ToDouble(txtPrice.Text);
            aGame.Discount      = Convert.ToInt32(txtDiscount.Text);
            aGame.DatePublished = calDatePublished.SelectedDate;
            aGame.Active        = chkActive.Checked;
            clsGamesCollection GamesList = new clsGamesCollection();
            if (GameId == -1)
            {
                GamesList.ThisGame = aGame;
                GamesList.Add();
            }
            else
            {
                GamesList.ThisGame.Find(GameId);
                GamesList.ThisGame = aGame;
                GamesList.Update();
            }
            Response.Redirect("GamesList.aspx");
        }
        else
        {
            lblError.Text = Error;
        }
    }
        public void AddMethodOK()
        {
            //create an instance of the class we want to create
            clsGamesCollection AllGames = new clsGamesCollection();
            //create th eitme of test data
            clsGames TestItem = new clsGames();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.Game_ID          = 1;
            TestItem.Game_Name        = "Areeb";
            TestItem.Game_Description = "This is my test data";
            TestItem.Game_Quantity    = 31;
            TestItem.Platform         = "Nintendo switch";
            TestItem.Supplier_ID      = 11;
            //set this game to the test data
            AllGames.ThisGame = TestItem;
            //add the record
            PrimaryKey = AllGames.Add();
            //set the primary key of the tst data
            TestItem.Game_ID = PrimaryKey;
            //find the rocrd
            AllGames.ThisGame.Find(PrimaryKey);
            //test to see that the 2 values are the same
            Assert.AreEqual(AllGames.ThisGame, TestItem);
        }
        public void DeleteMethodOK()
        {
            //crate an instance of the class we want to create
            clsGamesCollection AllGames = new clsGamesCollection();
            //crate the item of test data
            clsGames TestItem = new clsGames();

            //var to store the primry key
            Int32 Primarykey = 0;

            //set its properties
            TestItem.Game_ID          = 1;
            TestItem.Game_Name        = "Areeb";
            TestItem.Game_Description = "This is my tes data";
            TestItem.Game_Quantity    = 25;
            TestItem.Platform         = "PlayStation";
            TestItem.Supplier_ID      = 21;
            //set this game to the test data
            AllGames.ThisGame = TestItem;
            //add the record
            Primarykey = AllGames.Add();
            // set the primary key of the test data
            TestItem.Game_ID = Primarykey;
            //find the record
            AllGames.ThisGame.Find(Primarykey);
            //delete the record
            AllGames.Delete();
            //now find the record
            Boolean Found = AllGames.ThisGame.Find(Primarykey);

            //test to see that the record was not found
            Assert.IsFalse(Found);
        }
Example #4
0
        public void AddMethodOK()
        {
            clsGamesCollection AllGames = new clsGamesCollection();
            clsGame            TestGame = new clsGame();
            int PrimaryKey = 0;

            TestGame.GameTitle     = "Some Game";
            TestGame.Price         = 11.99;
            TestGame.Discount      = 20;
            TestGame.DatePublished = DateTime.Now.Date;
            TestGame.Active        = true;
            AllGames.ThisGame      = TestGame;
            PrimaryKey             = AllGames.Add();
            TestGame.GameId        = PrimaryKey;
            AllGames.ThisGame.Find(PrimaryKey);
            Assert.AreEqual(AllGames.ThisGame, TestGame);
        }
Example #5
0
        public void DeleteMethodOK()
        {
            clsGamesCollection AllGames = new clsGamesCollection();
            clsGame            TestGame = new clsGame();
            int PrimaryKey = 0;

            TestGame.GameTitle     = "Some Game";
            TestGame.Price         = 11.99;
            TestGame.Discount      = 20;
            TestGame.DatePublished = DateTime.Now.Date;
            TestGame.Active        = true;
            AllGames.ThisGame      = TestGame;
            PrimaryKey             = AllGames.Add();
            TestGame.GameId        = PrimaryKey;
            AllGames.ThisGame.Find(PrimaryKey);
            AllGames.Delete();
            bool Found = AllGames.ThisGame.Find(PrimaryKey);

            Assert.IsFalse(Found);
        }
        public void UpdateMethodOK()
        {
            //create an instance of the class we want to create
            clsGamesCollection AllGames = new clsGamesCollection();
            //create the item of test data
            clsGames TestItem = new clsGames();
            //var to store the primry key
            Int32 Primarykey = 0;

            //set its properties
            TestItem.Game_ID          = 1;
            TestItem.Game_Name        = "Areeb";
            TestItem.Game_Description = "This is my tes data";
            TestItem.Game_Quantity    = 25;
            TestItem.Platform         = "PlayStation";
            TestItem.Supplier_ID      = 21;
            //set this game to the test data
            AllGames.ThisGame = TestItem;
            //add the record
            Primarykey = AllGames.Add();
            // set the primary key of the test data
            TestItem.Game_ID = Primarykey;
            //modify the test data
            TestItem.Game_ID          = 2;
            TestItem.Game_Name        = "Beera";
            TestItem.Game_Description = "This is'nt my test data";
            TestItem.Game_Quantity    = 26;
            TestItem.Platform         = "PlayStation4";
            TestItem.Supplier_ID      = 22;
            //set the record based on the neew test data
            AllGames.ThisGame = TestItem;
            //update the record
            AllGames.Update();
            //find the record
            AllGames.ThisGame.Find(Primarykey);
            // test to see this game matches the test data
            Assert.AreEqual(AllGames.ThisGame, TestItem);
        }