protected void btnUpdate_Click(object sender, EventArgs e) { bool passRequirements = true; int producttypeid = Convert.ToInt32(txtProductTypeId.Text); ProductType pt2 = ProductTypeRepository.FindProductTypeById(producttypeid); String producttypename = txtProductTypeName.Text; ProductType pt = ProductTypeRepository.FindProductTypeByName(producttypename); if (txtProductTypeId.Text == "" || pt2 == null) { warningProductTypeId.Visible = true; passRequirements = false; } if (txtProductTypeName.Text == "" || producttypename.Length < 5 || pt != null) { passRequirements = false; warningProductTypeName.Visible = true; } if (txtDescription.Text == "") { passRequirements = false; warningDescription.Visible = true; } if (passRequirements == true) { String description = txtDescription.Text; ProductTypeRepository.Update(producttypeid, producttypename, description); Response.Redirect("Home.aspx"); } }
protected void btnInsert_Click(object sender, EventArgs e) { bool passRequirements = true; String producttypename = txtProductTypeName.Text; ProductType pt = ProductTypeRepository.FindProductTypeByName(producttypename); if (txtProductTypeName.Text == "" || producttypename.Length < 5 || pt != null) { passRequirements = false; warningProductTypeName.Visible = true; } if (txtDescription.Text == "") { passRequirements = false; warningDescription.Visible = true; } if (passRequirements == true) { String description = txtDescription.Text; ProductType newProductType = ProductTypeFactory.CreateProductType(producttypename, description); ProductTypeRepository.Create(newProductType); Response.Redirect("Home.aspx"); } }