public Employee GetEmployee(int id) { using (Model.PracticoNetEntities en = new Model.PracticoNetEntities()) { return(Casteo(en.Employee.Find(id))); } }
public void AddEmployee(Employee emp) { if (emp == null) { return; } using (Model.PracticoNetEntities en = new Model.PracticoNetEntities()) { en.Employee.Add(Casteo(emp)); en.SaveChanges(); } }
public List <Employee> GetAllEmployees() { using (Model.PracticoNetEntities en = new Model.PracticoNetEntities()) { List <Employee> listaEmpleados = new List <Employee>(); en.Employee.ToList().ForEach(x => { listaEmpleados.Add(Casteo(x)); }); return(listaEmpleados); } }
public void DeleteEmployee(int id) { using (var context = new Model.PracticoNetEntities()) { Model.Employee emp = context.Employee.FirstOrDefault(x => x.EmployeeId == id); if (emp != null) { if (emp.GetType().Name == "FullTimeEmployee") { Model.FullTimeEmployee fte = (Model.FullTimeEmployee)emp; context.Employee.Remove(fte); context.SaveChanges(); } else { Model.PartTimeEmployee pte = (Model.PartTimeEmployee)emp; context.Employee.Remove(pte); context.SaveChanges(); } } } }
public void UpdateEmployee(Employee emp) { if (emp == null) { return; } using (Model.PracticoNetEntities en = new Model.PracticoNetEntities()) { Model.Employee em = en.Employee.Find(emp.Id); em.Name = emp.Name; em.StartDate = emp.StartDate; if (emp.GetType().Name == "FullTimeEmployee") { Model.FullTimeEmployee emCast = (Model.FullTimeEmployee)em; emCast.Salary = ((FullTimeEmployee)emp).Salary; } else { Model.PartTimeEmployee emCast = (Model.PartTimeEmployee)em; emCast.HourlyRate = ((PartTimeEmployee)emp).HourlyRate; } en.SaveChanges(); } }