public List<Employee> GetAll() { List<Employee> allEmps = new List<Employee>(); try { DbContext ctx = new DbContext(); allEmps = ctx.Employees.AsQueryable().ToList(); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "GetAll"); } return allEmps; }
public Employee GetEmployeeBySurname(string name) { Employee retEmp = null; DbContext _ctx; try { _ctx = new DbContext(); var employees = _ctx.Employees; var employee = employees.AsQueryable<Employee>().Where(emp => emp.Lastname == name).FirstOrDefault(); retEmp = (Employee)employee; }catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "GetEmployeeBySurname"); } return retEmp; }
public Employee GetByID(string id) { Employee retEmp = null; ObjectId ID = new ObjectId(id); DbContext _ctx; try { _ctx = new DbContext(); retEmp = _ctx.Employees.AsQueryable().FirstOrDefault(e => e._id == ID); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "GetById"); } return retEmp; }
public Department GetDepartment(string idS) { ObjectId id = new ObjectId(idS); Department retDep = null; DbContext _ctx; try { _ctx = new DbContext(); var departments = _ctx.Departments; var department = departments.AsQueryable<Department>().Where(dep => dep._id == id).FirstOrDefault(); retDep = (Department)department; } catch (Exception ex) { Console.WriteLine("Problem " + ex.Message); } return retDep; }
/// <summary> /// Main Loading Method /// Revisions: Added Problem methods /// </summary> public bool LoadCollections() { bool createOk = false; try { DropAndCreateCollections(); ctx = new DbContext(); LoadDepartments(); LoadEmployees(); createOk = true; } catch (Exception ex) { Console.WriteLine(ex.Message); } return createOk; }
public int Update(Employee emp) { int updateOK = -1; try { DbContext ctx = new DbContext(); ctx.Save<Employee>(emp, "employees"); updateOK = 1; } catch (MongoConcurrencyException ex) { updateOK = -2; Console.WriteLine(ex.Message); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "Update"); } return updateOK; }
public Employee GetEmployeeBySurname(string name) { Employee retEmp = null; DbContext _ctx; try { _ctx = new DbContext(); var employees = _ctx.Employees; var employee = employees.AsQueryable<Employee>().FirstOrDefault(emp => emp.Lastname == name); retEmp = (Employee)employee; } catch(Exception ex) { Console.WriteLine("Problem " + ex.Message); } return retEmp; }
/// <summary> /// Main Loading Method /// Revisions: Added Problem methods /// </summary> public bool LoadCollections() { bool createOk = false; try { DropAndCreateCollections(); ctx = new DbContext(); LoadPics(); LoadDepartments(); LoadEmployees(); createOk = true; } catch (Exception ex) { ErrorRoutine(ex, "DALUtils", "LoadCollections"); } return createOk; }