protected void Button1_Click(object sender, EventArgs e) { PermanentEmployee permanantEmployee = new PermanentEmployee { FirstName = "Sunny", LastName = "Patel", Gender = "Male", AnnualSalary = 70000 }; EmployeeDBContext employeeDBContext = new EmployeeDBContext(); employeeDBContext.Employees.Add(permanantEmployee); employeeDBContext.SaveChanges(); }
protected void Button2_Click(object sender, EventArgs e) { ContractEmployee contractEmployee = new ContractEmployee { FirstName = "Chaya", LastName = "Patel", Gender = "Female", HourlyPay = 50, HoursWorked = 120 }; EmployeeDBContext employeeDBContext = new EmployeeDBContext(); employeeDBContext.Employees.Add(contractEmployee); employeeDBContext.SaveChanges(); }
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { EmployeeDBContext employeeDBContext = new EmployeeDBContext(); switch (RadioButtonList1.SelectedValue) { case "Permanent": GridView1.DataSource = employeeDBContext.Employees.OfType<PermanentEmployee>().ToList(); GridView1.DataBind(); break; case "Contract": GridView1.DataSource = employeeDBContext.Employees.OfType<ContractEmployee>().ToList(); GridView1.DataBind(); break; default: //Using ConvertEmployeesForDisplay method to diplay all employee details GridView1.DataSource = ConvertEmployeesForDisplay(employeeDBContext.Employees.ToList()); GridView1.DataBind(); break; } }
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { EmployeeDBContext employeeDBContext = new EmployeeDBContext(); switch (RadioButtonList1.SelectedValue) { case "Permanent": GridView1.DataSource = employeeDBContext.Employees.OfType <PermanentEmployee>().ToList(); GridView1.DataBind(); break; case "Contract": GridView1.DataSource = employeeDBContext.Employees.OfType <ContractEmployee>().ToList(); GridView1.DataBind(); break; default: //Using ConvertEmployeesForDisplay method to diplay all employee details GridView1.DataSource = ConvertEmployeesForDisplay(employeeDBContext.Employees.ToList()); GridView1.DataBind(); break; } }