Example #1
0
 public void UpdateEmployee(Employee emp)
 {
     using (Model.PracticoEntities en = new Model.PracticoEntities())
     {
         if (emp.GetType() == typeof(FullTimeEmployee))
         {
             FullTimeEmployee FullTimeEmp = (FullTimeEmployee)emp;
             Model.Employee   e           = en.EmployeeTPH.Find(emp.Id);
             if (e != null)
             {
                 Model.FullTimeEmployee empFT = (Model.FullTimeEmployee)e;
                 empFT.Name      = FullTimeEmp.Name;
                 empFT.Salary    = FullTimeEmp.Salary;
                 empFT.StartDate = FullTimeEmp.StartDate;
                 en.SaveChanges();
             }
         }
         else
         {
             PartTimeEmployee PartTimeEmp = (PartTimeEmployee)emp;
             Model.Employee   e           = en.EmployeeTPH.Find(emp.Id);
             if (e != null)
             {
                 Model.PartTimeEmployee empFT = (Model.PartTimeEmployee)e;
                 empFT.Name       = PartTimeEmp.Name;
                 empFT.StartDate  = PartTimeEmp.StartDate;
                 empFT.HourlyRate = PartTimeEmp.HourlyRate;
                 en.SaveChanges();
             }
         }
     }
 }
Example #2
0
 public void AddEmployee(Employee emp)
 {
     using (Model.PracticoEntities en = new Model.PracticoEntities())
     {
         Model.Employee empNuevo;
         if (emp.GetType() == typeof(FullTimeEmployee))
         {
             FullTimeEmployee empFT = (FullTimeEmployee)emp;
             empNuevo = new Model.FullTimeEmployee()
             {
                 EmployeeId = empFT.Id,
                 Name       = empFT.Name,
                 Salary     = empFT.Salary,
                 StartDate  = empFT.StartDate
             };
             en.EmployeeTPH.Add(empNuevo);
             en.SaveChanges();
         }
         else
         {
             PartTimeEmployee empPT = (PartTimeEmployee)emp;
             empNuevo = new Model.PartTimeEmployee()
             {
                 EmployeeId = empPT.Id,
                 Name       = empPT.Name,
                 StartDate  = empPT.StartDate,
                 HourlyRate = empPT.HourlyRate
             };
             en.EmployeeTPH.Add(empNuevo);
             en.SaveChanges();
         }
     }
 }