Esempio n. 1
0
 def delete_employee(employee_id):
     Database.set_engine()
     try:
         Database.open_connection()
         employee = EmployeeModel(employee_id, None, None, None, None)
         employee.delete()
     except Exception as ex:
         raise InvalidUsage(str(ex), status_code=500)
     finally:
         Database.close_connection()
     return json.dumps({'status':'ok',})
Esempio n. 2
0
 def delete_person(person_id):
     Database.create_session()
     try:
         Database.open_connection()
         EmployeeModel.delete_by_personid(person_id)
         person = PersonModel(person_id, None, None, None)
         person.delete()
         Database.session.commit()
     except Exception as ex:
         Database.session.rollback()
         raise InvalidUsage(str(ex), status_code=500)
     finally:
         Database.close_connection()
         Database.close_session()
     return json.dumps({'status':'ok'})
Esempio n. 3
0
 def get_person(person_id):
     Database.set_engine()
     person = PersonModel(person_id, None, None, None)
     try:
         Database.open_connection()
         person.getdata()
     except Exception as ex:
         raise InvalidUsage(str(ex), status_code=500)
     finally:
         Database.close_connection()
     return json.dumps({
         'person_id':person.person_id,
         'last_name':person.last_name,
         'first_name':person.first_name,
         'birth_date':datetime.strftime(person.birth_date, "%Y-%m-%d")})
Esempio n. 4
0
 def get_employee(employee_id):
     Database.set_engine()
     employee = EmployeeModel(employee_id, None, None, None, None)
     try:
         Database.open_connection()
         employee.getdata()
     except Exception as ex:
         raise InvalidUsage(str(ex), status_code=500)
     finally:
         Database.close_connection()
     return json.dumps({
         'employee_id':employee.employee_id,
         'person_id':employee.person_id,
         'employee_num':employee.employee_num,
         'employed_date':datetime.strftime(employee.employed_date, "%Y-%m-%d"),
         'terminated_date':datetime.strftime(employee.terminated_date, "%Y-%m-%d")})
Esempio n. 5
0
 def add_person(last_name, first_name, birth_date, person_id):
     Database.create_session()
     person = None
     try:
         Database.open_connection()
         person = PersonModel(person_id, last_name, first_name, birth_date)
         person.save()
         Database.session.commit()
     except Exception as ex:
         Database.session.rollback()
         raise InvalidUsage(str(ex), status_code=500)
     finally:
         Database.close_connection()
         Database.close_session()
     return json.dumps({'status':'ok', 'person_id':person.person_id, \
         'last_name':person.last_name, 'first_name':person.first_name,\
         'birth_date':datetime.strftime(person.birth_date, "%Y-%m-%d")})
Esempio n. 6
0
 def add_employee(employee_id, person_id, employee_num, employed_date, terminated_date):
     Database.create_session()
     employee = None
     try:
         Database.open_connection()
         employee = EmployeeModel(employee_id, person_id, employee_num, employed_date, terminated_date)
         employee.save()
         Database.session.commit()
     except Exception as ex:
         Database.session.rollback()
         raise InvalidUsage(str(ex), status_code=500)
     finally:
         Database.close_connection()
         Database.close_session()
     return json.dumps({'status':'ok', 'employee_id':employee.employee_id, 
         'person_id':employee.person_id, 'employee_num':employee.employee_num,\
         'employed_date':datetime.strftime(employee.employed_date, "%Y-%m-%d"),\
         'terminated_date':datetime.strftime(employee.terminated_date, "%Y-%m-%d")
                        })