private void buttonOK_Click(object sender, EventArgs e) { var createFormEntity = new CreateFormEntity(); createFormEntity.FirstName = this.textBoxFirstName.Text; createFormEntity.LastName = this.textBoxLastName.Text; createFormEntity.Birthday = this.textBoxBirthday.Text; createFormEntity.Position = this.textBoxPosition.Text; createFormEntity.Salary = this.textBoxSalary.Text; String errorMessage; if (createFormEntity.IsValid(out errorMessage)) { var employee = FillEmployee(createFormEntity); if (ValidatorEmployee.IsValid(employee, out errorMessage)) { OnEmployeePassedValidation(new NewEmployeeEventArgs(employee)); this.Close(); } else { this.labelError.Text = errorMessage; SetPositionLabelError(); } } else { this.labelError.Text = errorMessage; SetPositionLabelError(); } }
private Employee FillEmployee(CreateFormEntity createFormEntity) { var employee = new Employee(); employee.FirstName = createFormEntity.FirstName; employee.LastName = createFormEntity.LastName; employee.Birthday = createFormEntity.Birthday; var emplPosition = new Position(employee); emplPosition.Name = createFormEntity.Position; var salareEmpl = new Salary(emplPosition); salareEmpl.Value = Convert.ToInt32(createFormEntity.Salary); employee.Positions.Add(emplPosition); return(employee); }