//function for adding new records void Add() { //create an instance of the address book clsCostumerCollection AddressBook = new clsCostumerCollection(); //validate the data on the web form String Error = AddressBook.ThisAddress.Valid(txtCostumerID Text, txtName Text, txtCostumerAddress Text, txtCostumerDOB Text, txtEmail Text); //if the data is OK then add it to the object if (Error == "") { //get the data entered by the user clsCostumerCollection AddressBook = new clsCostumerCollection(); txtCostumerID.Text = ACostumer.CostumerID.ToString(); txtName.Text = ACostumer.Name.ToString(); txtCostumerAddress.Text = ACostumer.CostumerAddress.ToString(); txtCostumerDOB.Text = ACostumer.CostumerDOB.ToString(); txtEmail.Text = ACostumer.Email.ToString(); //add the record AddressBook.Add(); //all done so redirect back to the main page Response.Redirect("CostumerList.aspx"); } else { //report an error lblError.Text = "There were problems with the data entered " + Error; } }
public void AddMethodOK() { clsCostumerCollection AllCostumers = new clsCostumerCollection(); clsCostumer TestItem = new clsCostumer(); int PrimaryKey = 0; TestCostumer.CostumerID = 1; TestCostumer.Name = "James"; TestCostumer.CostumerAddress = "40 Glenfield Road"; TestCostumer.CostumerDOB = DateTime.Now.Date; TestCostumer.Email = "*****@*****.**"; TestCostumer.Active = true; AllCostumers.ThisCostumer = TestItem; PrimaryKey = AllCostumers.Add(); AllCostumers.ThisCostumer.Find(PrimaryKey); Assert.AreEqual(AllCostumers.ThisCostumer, TestItem); }
public void DeleteMethodOK() { clsCostumerCollection AllCostumers = new clsCostumerCollection(); clsCostumer TestCostumer = new clsCostumer(); int PrimaryKey = 0; TestCostumer.CostumerID = 1; TestCostumer.Name = "James"; TestCostumer.CostumerAddress = "40 Glenfield Road"; TestCostumer.CostumerDOB = DateTime.Now.Date; TestCostumer.Email = "*****@*****.**"; TestCostumer.Active = true; PrimaryKey = AllCostumers.Add(); TestCostumer.CostumerID = PrimaryKey; AllCostumers.ThisCostumer.Find(PrimaryKey); AllCostumers.Delete(); Boolean Found = AllCostumers.ThisCostumer.Find(PrimaryKey); Assert.IsFalse(Found); }