Beispiel #1
0
 public Employee GetEmployee(int id)
 {
     using (Model.PracticoNetEntities en = new Model.PracticoNetEntities())
     {
         return(Casteo(en.Employee.Find(id)));
     }
 }
Beispiel #2
0
 public void AddEmployee(Employee emp)
 {
     if (emp == null)
     {
         return;
     }
     using (Model.PracticoNetEntities en = new Model.PracticoNetEntities())
     {
         en.Employee.Add(Casteo(emp));
         en.SaveChanges();
     }
 }
Beispiel #3
0
 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);
     }
 }
Beispiel #4
0
 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();
             }
         }
     }
 }
Beispiel #5
0
 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();
     }
 }