private void btnSave_Click(object sender, EventArgs e) { if (ValidateSupplier()) { if (this.IsIndividualEntity) //If it's an individual entity { if (IndividualEntity.IsFromPR(this.SelectedCompany)) //And the company it attends is from PR { if (IndividualEntity.HasLegalAge(dtpBirthDate.Value.Date)) //Check if it is at least 18 y/o { if (this.IndividualEntities != null) { var individualSuppliers = new List <IndividualEntity>(this.IndividualEntities); individualSuppliers.Add(SaveIndividualEntitySupplier()); this.IndividualEntities = individualSuppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { var individualSuppliers = new List <IndividualEntity>(); individualSuppliers.Add(SaveIndividualEntitySupplier()); this.IndividualEntities = individualSuppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { MessageBox.Show("Individual entity suppliers must be at least 18 years old", "Supplier not old enough", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else //else, if it is not from PR, there's no need to be 18 years old { if (this.IndividualEntities != null) { var individualSuppliers = new List <IndividualEntity>(this.IndividualEntities); individualSuppliers.Add(SaveIndividualEntitySupplier()); this.IndividualEntities = individualSuppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { var individualSuppliers = new List <IndividualEntity>(); individualSuppliers.Add(SaveIndividualEntitySupplier()); this.IndividualEntities = individualSuppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } } else // else, if it is a legal entity supplier { if (this.Suppliers != null) { var suppliers = new List <Supplier>(this.Suppliers); suppliers.Add(SaveLegalEntitySupplier()); this.Suppliers = suppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { var suppliers = new List <Supplier>(); suppliers.Add(SaveLegalEntitySupplier()); this.Suppliers = suppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } } }