Exemplo n.º 1
0
 public void Edit(Employee p)
 {
     if ( p != null ) {
         accion = ETipoAccion.EDIT;
         ValidateEmployeeProperty(p);
         db.Entry(p).State = EntityState.Modified;
     }
     else
         throw new ArgumentNullException("Employee");
 }
Exemplo n.º 2
0
 public Employee Retrieve(Employee p)
 {
     Employee po = null;
     if ( p.EmployeeID != null ) {
         po = db.Employee.FirstOrDefault(x => x.EmployeeID == p.EmployeeID);
     }
     if ( p == null ) {
         po = db.Employee.Find(p);
     }
     return po;
 }
Exemplo n.º 3
0
        public ActionResult Create(Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employee.Add(employee);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(employee);
        }
Exemplo n.º 4
0
 public void Delete(Employee p)
 {
     if ( p != null ) {
         accion = ETipoAccion.DELETE;
         ValidateEmployeeProperty(p);
         db.Employee.Remove(p); ;
         db.SaveChanges();
       }
     else {
         throw new ArgumentNullException("Employee");
     }
 }
Exemplo n.º 5
0
 public Employee Create(Employee p)
 {
     if ( p != null  && p.Person!=null) {
         accion = ETipoAccion.CREATE;
         ValidateEmployeeProperty(p);
         db.Employee.Add(p);
         db.SaveChanges();
         return db.Employee.FirstOrDefault(x => x.Person.ID == p.Person.ID);
     }
     else {
         throw new ArgumentNullException("Employee");
     }
 }
Exemplo n.º 6
0
        public Employee RetrieveComplete(Employee p)
        {
            if ( p != null  && p.EmployeeID!=null && p.EmployeeID>0) {

                var po =(from e in db.Employee.Include("Person")
                         where e.EmployeeID==p.EmployeeID
                          select e).FirstOrDefault();
                //var po = (from e in db.Employee
                //          join per in db.Person
                //          on e.Person.ID equals per.ID
                //          where e.EmployeeID == p.EmployeeID
                //          select new Employee {
                //              EmployeeID = e.EmployeeID,
                //              PayMent = e.PayMent,
                //              Position = e.Position,
                //              Person = per
                //          });

                return po;
            }
            else {
                return null;
            }
        }
Exemplo n.º 7
0
        private void ValidateEmployeeProperty(Employee p)
        {
            switch ( accion ) {
                case ETipoAccion.CREATE:
                    if ( p == null || p.EmployeeID == null || p.Person == null || p.Person.ID == null ) {
                        throw new DbEntityValidationException("EmployeeID,PersonID");

                    }
                    break;
                case ETipoAccion.EDIT:

                    if ( p == null || p.EmployeeID == null || p.Person == null || p.Person.ID == null ) {
                        throw new DbEntityValidationException("EmployeeID,PersonID");

                    }
                    break;
                case ETipoAccion.DELETE:

                    if ( p == null || p.EmployeeID == null ) {
                        throw new DbEntityValidationException("EmployeeID,PersonID");

                    }
                    break;
                default:
                    break;
            }
            return;
        }
Exemplo n.º 8
0
        public List<Employee> RetrieveEmployees(Employee p)
        {
            if ( p != null ) {

                long? eId = p.EmployeeID != null ? p.EmployeeID : null;
                long? id = p.Person != null && p.Person.ID != null ? p.Person.ID : null;
                List<Employee> ls = null;
                if ( eId != null ) {
                    ls = db.Employee.Where(x => x.EmployeeID == eId).ToList<Employee>();

                }
                if ( id != null ) {
                    if ( ls != null && ls.Count >= 1 ) {
                        ls = ls.Where(x => x.Person.ID == p.Person.ID).ToList<Employee>();
                    }
                    else {
                        ls = db.Employee.Where(x => x.Person.ID == p.Person.ID).ToList<Employee>();
                    }
                }

                return ls.ToList<Employee>();
            }
            else {
              return  db.Employee.ToList<Employee>();
            }
        }
Exemplo n.º 9
0
        public List<Employee> RetrieveEmployees()
        {
            var em = db.Employee;
            List<Employee> ls = new List<Employee>();

               foreach (Employee item in em ) {

               Employee emp = new Employee();
               emp = RetrieveComplete(item);
               ls.Add(emp);

               }
               return ls;
        }
Exemplo n.º 10
0
 public ActionResult Edit(Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(employee);
 }