protected void btnOK_Click(object sender, EventArgs e) { var aPolicy = new clsPolicy(); aPolicy.PolicyId = int.Parse(txtPolicyId.Text); var staffId = txtStaffId.Text; var customerId = txtCustomerId.Text; var price = txtPrice.Text; var policeDetails = txtPolicyDetails.Text; var startDate = calStartDate.SelectedDate.ToString(); var error = aPolicy.Valid(staffId, customerId, policeDetails, startDate, price); if (error == "") { //capture policy id aPolicy.PolicyId = PolicyId; aPolicy.StaffId = int.Parse(txtStaffId.Text); aPolicy.CustomerId = int.Parse(txtCustomerId.Text); aPolicy.Price = decimal.Parse(Convert.ToDecimal(txtPrice.Text).ToString("N2")); aPolicy.StartDate = calStartDate.SelectedDate; aPolicy.PolicyDetails = txtPolicyDetails.Text; aPolicy.Accepted = Convert.ToBoolean(chkAccepted.Checked); // Session["APolicy"] = aPolicy; //create a new instance of the policy collection var policyList = new clsPolicyCollection(); //if this is a new record if (PolicyId == -1) { //set the ThisPolicy property policyList.ThisPolicy = aPolicy; //add new record policyList.Add(); } //otherwise it must be an update else { //find record policyList.ThisPolicy.Find(PolicyId); //set the ThisPolicy property policyList.ThisPolicy = aPolicy; //update the record policyList.Update(); } //redirect back to listpage Response.Redirect("PolicyList.aspx"); // Response.Redirect("PolicyViewer.aspx"); } else { lblError.Text = error; } }
public void UpdateMethodOk() { //instance of class var allPolicies = new clsPolicyCollection(); //create an item of test data var testItem = new clsPolicy(); //store the PK var primaryKey = 0; //set the properties testItem.Accepted = true; testItem.CustomerId = 111; testItem.PolicyDetails = "Lorem ipsum dolor sit amet,"; testItem.PolicyId = 112; testItem.Price = 64.00M; testItem.StaffId = 68; testItem.StartDate = DateTime.Now.Date; //set the ThisPolicy to test data allPolicies.ThisPolicy = testItem; //add record primaryKey = allPolicies.Add(); //set the PK of the test data testItem.PolicyId = primaryKey; //modify test data testItem.Accepted = false; testItem.CustomerId = 112; testItem.PolicyDetails = "Lorem ipsum"; testItem.PolicyId = 110; testItem.Price = 65.00M; testItem.StaffId = 69; testItem.StartDate = DateTime.Now.Date; //set the record based on the new test data allPolicies.ThisPolicy = testItem; //update the record allPolicies.Update(); //find the record allPolicies.ThisPolicy.Find(primaryKey); var found = allPolicies.ThisPolicy.Find(primaryKey); //test to see that the record was not found Assert.AreEqual(allPolicies.ThisPolicy, testItem); }