private void btnSave_Click(object sender, EventArgs e) { TBL_MP_Master_Employee model = null; ServiceEmployee serviceEmployee = new ServiceEmployee(); try { if (!this.ValidateChildren()) { return; } if (this.EmployeeID == 0) { model = new TBL_MP_Master_Employee(); } else { model = serviceEmployee.GetEmployeeDbRecordByID(this.EmployeeID); } #region GATHER DATA INTO MODEL FROM VIEW model.EmployeeCode = txtEmployeeCode.Text; model.EmployeeName = txtEmployeeName.Text; model.EmailAddress = txtEmail.Text; model.PhoneNo1 = txtMobileNo.Text; model.FK_DepartmentId = ((SelectListItem)cboDepartment.SelectedItem).ID; model.FK_DesignationId = ((SelectListItem)cboDesignation.SelectedItem).ID; model.FK_EmploymentTypeID = ((SelectListItem)cboEmploymentType.SelectedItem).ID; model.isActive = chkIsActive.Checked; model.IsResigned = chkHasResigned.Checked; model.FK_BossID = ((SelectListItem)cboEmployeeBoss.SelectedItem).ID; #endregion if (this.EmployeeID == 0) { //CREATE EMPLOYEE model.FK_CompanyID = Program.CURR_USER.CompanyID; model.FK_YearID = Program.CURR_USER.FinYearID; model.FK_BranchID = Program.CURR_USER.BranchID; model.CreatedBy = Program.CURR_USER.EmployeeID; model.CreatedDateTime = AppCommon.GetServerDateTime(); this.EmployeeID = serviceEmployee.AddNewEmployee(model); } else { model.ModifiedBy = Program.CURR_USER.EmployeeID; model.ModifiedDateTime = AppCommon.GetServerDateTime(); serviceEmployee.UpdateEmployee(model); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditEmployee::btnSave_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }