Beispiel #1
0
 public void UpdateEmployee(Employee emp)
 {
     using (Model.TESTEntities DB = new Model.TESTEntities()) {
         if (emp != null)
         {
             if (emp != null)
             {
                 Model.Employee EmpDB = DB.Employees.Find(emp.Id);
                 if (EmpDB is Model.PartTimeEmployee)
                 {
                     PartTimeEmployee       empLP = (PartTimeEmployee)emp;
                     Model.PartTimeEmployee nuevo = (Model.PartTimeEmployee)EmpDB;
                     nuevo.Name       = empLP.Name;
                     nuevo.StartDate  = empLP.StartDate;
                     nuevo.HourlyRate = empLP.HourlyRate;
                     DB.Employees.Attach(nuevo);
                 }
                 else
                 {
                     FullTimeEmployee       empLP = (FullTimeEmployee)emp;
                     Model.FullTimeEmployee nuevo = (Model.FullTimeEmployee)EmpDB;
                     nuevo.Name      = empLP.Name;
                     nuevo.StartDate = empLP.StartDate;
                     nuevo.Salary    = empLP.Salary;
                     DB.Employees.Attach(nuevo);
                 }
                 DB.SaveChanges();
             }
         }
     }
 }
Beispiel #2
0
 public void AddEmployee(Employee emp)
 {
     using (Model.TESTEntities DB = new Model.TESTEntities())
     {
         if (emp is PartTimeEmployee)
         {
             PartTimeEmployee       empLP = new PartTimeEmployee();
             Model.PartTimeEmployee nuevo = new Model.PartTimeEmployee();
             nuevo.EmployeeId = empLP.Id;
             nuevo.Name       = empLP.Name;
             nuevo.StartDate  = empLP.StartDate;
             nuevo.HourlyRate = empLP.HourlyRate;
             DB.Employees.Add(nuevo);
         }
         else
         {
             FullTimeEmployee       empLP = new FullTimeEmployee();
             Model.FullTimeEmployee nuevo = new Model.FullTimeEmployee();
             nuevo.EmployeeId = empLP.Id;
             nuevo.Name       = empLP.Name;
             nuevo.StartDate  = empLP.StartDate;
             nuevo.Salary     = empLP.Salary;
             DB.Employees.Add(nuevo);
         }
         DB.SaveChanges();
     }
 }
Beispiel #3
0
 public void DeleteEmployee(int id)
 {
     using (Model.TESTEntities DB = new Model.TESTEntities())
     {
         DB.Employees.Remove(DB.Employees.Find(id));
         DB.SaveChanges();
     }
 }