public void AddEmployee(Employee emp) { using (Model.PracticoObligatorioEntities en = new Model.PracticoObligatorioEntities()) { if (emp.GetType().Name == "FullTimeEmployee") { FullTimeEmployee employee = (FullTimeEmployee)emp; Model.FullTimeEmployee employeeBase = new Model.FullTimeEmployee() { Name = employee.Name, StartDate = employee.StartDate, Salary = employee.Salary }; en.EmployeesTPH.Add(employeeBase); en.SaveChanges(); } else { PartTimeEmployee employee = (PartTimeEmployee)emp; Model.PartTimeEmployee employeeBase = new Model.PartTimeEmployee() { Name = employee.Name, StartDate = employee.StartDate, HourlyRate = employee.HourlyRate }; en.EmployeesTPH.Add(employeeBase); en.SaveChanges(); } } }
public void DeleteEmployee(int id) { using (Model.PracticoObligatorioEntities en = new Model.PracticoObligatorioEntities()) { en.EmployeesTPH.Remove(en.EmployeesTPH.Find(id)); en.SaveChanges(); } }
public void UpdateEmployee(Employee emp) { using (Model.PracticoObligatorioEntities en = new Model.PracticoObligatorioEntities()) { if (emp.GetType().Name == "FullTimeEmployee") { FullTimeEmployee empleado = (FullTimeEmployee)emp; Model.FullTimeEmployee empleadoBase = (Model.FullTimeEmployee)en.EmployeesTPH.Find(emp.Id); empleadoBase.Name = empleado.Name; empleadoBase.StartDate = empleado.StartDate; empleadoBase.Salary = empleado.Salary; en.SaveChanges(); } else { PartTimeEmployee empleado = (PartTimeEmployee)emp; Model.PartTimeEmployee empleadoBase = (Model.PartTimeEmployee)en.EmployeesTPH.Find(emp.Id); empleadoBase.Name = empleado.Name; empleadoBase.StartDate = empleado.StartDate; empleadoBase.HourlyRate = empleado.HourlyRate; en.SaveChanges(); } } }