Example #1
0
    //function for update
    void Update()
    {
        //create an instance of the menu item book
        clsMenuItemCollection MenuItemBook = new clsMenuItemCollection();
        //validate the data on the web form
        String Error = MenuItemBook.ThisMenuItem.Valid(txtMenuItem.Text, txtPrice.Text);

        //if the data is OK then add it to the object
        if (Error == "")
        {
            //find the record to update
            MenuItemBook.ThisMenuItem.Find(MenuItemNo);
            // get the data entered by the user
            MenuItemBook.ThisMenuItem.MenuItem      = txtMenuItem.Text;
            MenuItemBook.ThisMenuItem.MenuItemPrice = Convert.ToInt32(txtPrice.Text);
            //update the record
            MenuItemBook.Update();
            // redirect back to the main page
            Response.Redirect("MenuDefault.aspx");
        }
        else
        {
            // report an error
            lblError.Text = "There were too many problems with the data entered " + Error;
        }
    }
Example #2
0
        public void UpdateMethodOK()
        {
            //create an instance of the class
            clsMenuItemCollection AllMenuItems = new clsMenuItemCollection();
            // create some test data to assign to the property
            clsMenuItem TestItem = new clsMenuItem();
            // var to store the primary key
            Int32 PrimaryKey = 0;

            // set the properties of the test object
            TestItem.MenuItem      = "Grapes";
            TestItem.MenuItemPrice = 4;
            // set this menu item to the test data
            AllMenuItems.ThisMenuItem = TestItem;
            // add the record
            PrimaryKey = AllMenuItems.Add();
            // set the primary key of the test data
            TestItem.MenuItemNo = PrimaryKey;
            // modify the test data
            TestItem.MenuItem      = "Qiwi";
            TestItem.MenuItemPrice = 2;
            // set the record based on the new test data
            AllMenuItems.ThisMenuItem = TestItem;
            // update the record
            AllMenuItems.Update();
            // find the record
            AllMenuItems.ThisMenuItem.Find(PrimaryKey);
            // test to see that the two values are the same
            Assert.AreEqual(AllMenuItems.ThisMenuItem, TestItem);
        }