protected void ButtonAddEmployee_Click(object sender, EventArgs e) { ClearAlerts(); try { int cid = int.Parse(ddlContact.SelectedValue); decimal salary = 0, hourlyRate = 0; decimal.TryParse(TextBoxSalary.Text, out salary); decimal.TryParse(TextBoxHourlyRate.Text, out hourlyRate); var newEmployee = new Employee() { contactID = cid, employeeNumber = TextBoxEmployeeNumber.Text, salary = salary, hourlyRate = hourlyRate, startDate = DateTime.Parse(TextBoxStartDate.Text) }; theGateContext.Employees.Add(newEmployee); theGateContext.SaveChanges(); TextBoxEmployeeNumber.Text = string.Empty; TextBoxSalary.Text = string.Empty; TextBoxHourlyRate.Text = string.Empty; TextBoxStartDate.Text = string.Empty; ddlContact.SelectedIndex = 0; LoadEmployees(); } catch (Exception ex) { PanelAddAlertError.Visible = true; LabelAddAlert.Text = "Error adding new employee: " + ex.Message; } }
protected string GetContactName(Employee em) { var contact = theGateContext.Contacts.Where(c => c.contactID == em.contactID).FirstOrDefault(); if (contact != null) return contact.firstName + " " + contact.lastName; else return string.Empty; }