void Update() { //create an instance clsCarRepairsCollection CarRepair = new clsCarRepairsCollection(); //validate the data on webform Boolean OK = CarRepair.ThisCarRepair.Valid(txtMechanicDaysInForRepair.Text, txtMechanicDeadlineDate.Text, txtMechanicPartPrice.Text, txtMechanicPartRequired.Text, txtMechanicCarID.Text, txtMechanicStaffID.Text); //if data is okay then add to object if (OK == true) { //Find record to update CarRepair.ThisCarRepair.Find(CarRepairID); //Fetch data entered by user CarRepair.ThisCarRepair.DaysInForRepair = Convert.ToInt32(txtMechanicDaysInForRepair.Text); CarRepair.ThisCarRepair.DeadlineDate = Convert.ToDateTime(txtMechanicDeadlineDate.Text); CarRepair.ThisCarRepair.PartPrice = Convert.ToDecimal(txtMechanicPartPrice.Text); CarRepair.ThisCarRepair.PartRequired = txtMechanicPartRequired.Text; CarRepair.ThisCarRepair.CarID = Convert.ToInt32(txtMechanicCarID.Text); CarRepair.ThisCarRepair.StaffID = Convert.ToInt32(txtMechanicStaffID.Text); //update record CarRepair.Update(); Response.Redirect("MechanicHomepage.aspx"); lblMechanicError.Text = "Repair successfully added"; } else { //report error lblMechanicError.Text = "There were problems with the data you have entered, please try again"; } }
public void UpdateMethodOK() { //Create an instance of the class clsCarRepairsCollection AllCarRepairs = new clsCarRepairsCollection(); //create the item of test data clsCarRepairs TestItem = new clsCarRepairs(); //Var to store the primary key Int32 PrimaryKey = 0; //Set its properties TestItem.DaysInForRepair = 1; TestItem.DeadlineDate = DateTime.Now.Date.AddDays(9); TestItem.PartPrice = 200.00m; TestItem.PartRequired = "4 new tyres"; //set this repair to the test data AllCarRepairs.ThisCarRepair = TestItem; //add the record PrimaryKey = AllCarRepairs.Add(); //set the primary key of the test data TestItem.CarRepairID = PrimaryKey; //Modify the data TestItem.DaysInForRepair = 2; TestItem.DeadlineDate = DateTime.Now.Date.AddDays(12); TestItem.PartPrice = 210.00m; TestItem.PartRequired = "7 new tyres"; //set this repair to the new test data AllCarRepairs.ThisCarRepair = TestItem; //Update the record AllCarRepairs.Update(); //find the record AllCarRepairs.ThisCarRepair.Find(PrimaryKey); //Test to see if the two values are the same Assert.AreEqual(AllCarRepairs.ThisCarRepair, TestItem); }