Ejemplo n.º 1
0
        public List <Employee> GetAllEmployees()
        {
            List <Employee> lista = new List <Employee>();

            using (Model.TESTEntities DB = new Model.TESTEntities())
            {
                var ListEmp = (from e in DB.Employees select e).ToList();
                foreach (Model.Employee emp in ListEmp)
                {
                    if (emp is Model.PartTimeEmployee)
                    {
                        Model.PartTimeEmployee empDB = (Model.PartTimeEmployee)emp;
                        PartTimeEmployee       nuevo = new PartTimeEmployee();
                        nuevo.Id         = empDB.EmployeeId;
                        nuevo.Name       = empDB.Name;
                        nuevo.StartDate  = empDB.StartDate;
                        nuevo.HourlyRate = (Double)empDB.HourlyRate;
                        lista.Add(nuevo);
                    }
                    else
                    {
                        Model.FullTimeEmployee empDB = (Model.FullTimeEmployee)emp;
                        FullTimeEmployee       nuevo = new FullTimeEmployee();
                        nuevo.Id        = empDB.EmployeeId;
                        nuevo.Name      = empDB.Name;
                        nuevo.StartDate = empDB.StartDate;
                        nuevo.Salary    = (int)empDB.Salary;
                        lista.Add(nuevo);
                    }
                }
            }
            return(lista);
        }
Ejemplo n.º 2
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();
             }
         }
     }
 }
Ejemplo n.º 3
0
 public Employee GetEmployee(int id)
 {
     using (Model.TESTEntities DB = new Model.TESTEntities())
     {
         var ListEmp = (from e in DB.Employees where e.EmployeeId == id select e).ToList();
         foreach (Model.Employee emp in ListEmp)
         {
             if (emp is Model.PartTimeEmployee)
             {
                 Model.PartTimeEmployee empDB = (Model.PartTimeEmployee)emp;
                 PartTimeEmployee       nuevo = new PartTimeEmployee();
                 nuevo.Id         = empDB.EmployeeId;
                 nuevo.Name       = empDB.Name;
                 nuevo.StartDate  = empDB.StartDate;
                 nuevo.HourlyRate = (Double)empDB.HourlyRate;
                 return(nuevo);
             }
             else
             {
                 Model.FullTimeEmployee empDB = (Model.FullTimeEmployee)emp;
                 FullTimeEmployee       nuevo = new FullTimeEmployee();
                 nuevo.Id        = empDB.EmployeeId;
                 nuevo.Name      = empDB.Name;
                 nuevo.StartDate = empDB.StartDate;
                 nuevo.Salary    = (int)empDB.Salary;
                 return(nuevo);
             }
         }
         return(null);
     }
 }
Ejemplo n.º 4
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();
     }
 }
Ejemplo n.º 5
0
 public void DeleteEmployee(int id)
 {
     using (Model.TESTEntities DB = new Model.TESTEntities())
     {
         DB.Employees.Remove(DB.Employees.Find(id));
         DB.SaveChanges();
     }
 }