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;
        }
    }
Exemple #2
0
    void Update()
    {
        //create an instance of the gamesstore
        clsGamesCollection GamesStore = new clsGamesCollection();
        //validate the data on the web form
        String Error = GamesStore.ThisGame.Valid(txtGame_Name.Text, txtGame_Description.Text, txtGame_Quantity.Text, txtPlatform.Text, txtSupplier_ID.Text);

        //if the ata is ok then add it to the object
        if (Error == "")
        {
            GamesStore.ThisGame.Find(Game_ID);
            //get the data entered by the user
            GamesStore.ThisGame.Game_Name        = txtGame_Name.Text;
            GamesStore.ThisGame.Game_Description = txtGame_Description.Text;
            GamesStore.ThisGame.Game_Quantity    = Convert.ToInt32(txtGame_Quantity.Text);
            GamesStore.ThisGame.Platform         = txtPlatform.Text;
            GamesStore.ThisGame.Supplier_ID      = Convert.ToInt32(txtSupplier_ID.Text);
            //update the record
            GamesStore.Update();
            Response.Redirect("Default.aspx");
        }

        else
        {
            //report an error
            lblError.Text = "There was a problem" + Error;
        }
    }
        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);
        }
Exemple #4
0
        public void UpdateMethodOK()
        {
            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;
            TestGame.GameTitle     = "Another Game";
            TestGame.Price         = 7.99;
            TestGame.Discount      = 0;
            TestGame.DatePublished = DateTime.Now.Date;
            TestGame.Active        = true;
            AllGames.ThisGame      = TestGame;
            AllGames.Update();
            AllGames.ThisGame.Find(PrimaryKey);
            Assert.AreEqual(AllGames.ThisGame, TestGame);
        }