public List<Department> GetAll() { List<Department> allDeps = new List<Department>(); try { DbContext ctx = new DbContext(); allDeps = ctx.Departments.ToList(); } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "DepartmentDAO", "GetAll"); } return allDeps; }
public List<Problem> GetAll() { List<Problem> allPrbs = new List<Problem>(); try { DbContext ctx = new DbContext(); allPrbs = ctx.Problems.ToList(); } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "ProblemDAO", "GetAll"); } return allPrbs; }
// Method Name: Create // Purpose: Add an Employee document to the employees collection // Accepts: An employee object // Returns: A string public string Create(Employee emp) { string newid = ""; try { DbContext ctx = new DbContext(); ctx.Save(emp, "employees"); newid = emp._id.ToString(); } catch(Exception e) { DALUtils.ErrorRoutine(e, "EmployeeDAO", "Create"); } return newid; }
public List<Employee> GetAll() { List<Employee> allEmps = new List<Employee>(); try { DbContext ctx = new DbContext(); allEmps = ctx.Employees.ToList(); } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "EmployeeDAO", "GetAll"); } return allEmps; }
public string Create(Problem prb) { string newid = ""; try { DbContext ctx = new DbContext(); ctx.Save(prb, "problems"); newid = prb._id.ToString(); } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "ProblemDAO", "Create"); } return newid; }
public string Create(Department dep) { string newid = ""; try { DbContext ctx = new DbContext(); ctx.Save(dep, "departments"); newid = dep._id.ToString(); } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "DepartmentDAO", "Create"); } return newid; }
// Method Name: Delete // Purpose: Deletes an employee object from the database // Accepts: a String // Returns: bool public bool Delete(string id) { bool deleteOk = false; ObjectId empid = new ObjectId(id); try { DbContext ctx = new DbContext(); Employee emp = ctx.Employees.FirstOrDefault(e => e._id == empid); ctx.Delete<Employee>(emp, "employees"); deleteOk = true; } catch(Exception e) { DALUtils.ErrorRoutine(e, "EmployeeDAO", "Delete"); } return deleteOk; }
public bool Delete(string id) { bool deleteOk = false; ObjectId depId = new ObjectId(id); try { DbContext ctx = new DbContext(); Department dep = ctx.Departments.FirstOrDefault(d => d._id == depId); ctx.Delete<Department>(dep, "departments"); deleteOk = true; } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "DepartmentDAO", "Delete"); } return deleteOk; }
public Problem GetByID(string id) { Problem retPrb = null; ObjectId ID = new ObjectId(id); DbContext _ctx; try { _ctx = new DbContext(); retPrb = _ctx.Problems.FirstOrDefault(p => p._id == ID); } catch (Exception ex) { Console.WriteLine("Problem " + ex.Message); } return retPrb; }
public Department GetByID(string id) { Department retDep = null; ObjectId ID = new ObjectId(id); DbContext _ctx; try { _ctx = new DbContext(); retDep = _ctx.Departments.FirstOrDefault(d => d._id == ID); } catch (Exception ex) { Console.WriteLine("Problem " + ex.Message); } return retDep; }
public bool Delete(string id) { bool deleteOk = false; ObjectId prbId = new ObjectId(id); try { DbContext ctx = new DbContext(); Problem prb = ctx.Problems.FirstOrDefault(p => p._id == prbId); ctx.Delete<Problem>(prb, "problems"); deleteOk = true; } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "ProblemDAO", "Delete"); } return deleteOk; }
public Employee GetByID(string id) { Employee retEmp = null; ObjectId ID = new ObjectId(id); DbContext _ctx; try { _ctx = new DbContext(); retEmp = _ctx.Employees.FirstOrDefault(e => e._id == ID); } 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(); LoadDepartments(); LoadEmployees(); LoadProblems(); createOk = true; } catch (Exception ex) { Console.WriteLine(ex.Message); } return createOk; }
public int Update(Employee emp) { int update = -1; try { DbContext ctx = new DbContext(); ctx.Save<Employee>(emp, "employees"); update = 1; } catch (MongoConcurrencyException ex) { update = -2; } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "EmployeeDAO", "Update:Error"); } return update; }
public Problem GetByName(string name) { Problem retPrb= null; DbContext _ctx; try { _ctx = new DbContext(); var problems = _ctx.Problems; var problem = problems.AsQueryable<Problem>().Where(prb => prb.Description == name).FirstOrDefault(); retPrb = (Problem)problem; } catch (Exception ex) { Console.WriteLine("Problem " + ex.Message); } return retPrb; }
public int Update(Problem prb) { int update = -1; try { DbContext ctx = new DbContext(); ctx.Save<Problem>(prb, "problems"); update = 1; } catch (MongoConcurrencyException ex) { update = -2; } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "ProblemDAO", "Update:Error"); } return update; }
public int Update(Department dep) { int update = -1; try { DbContext ctx = new DbContext(); ctx.Save<Department>(dep, "departments"); update = 1; } catch (MongoConcurrencyException ex) { update = -2; } catch (Exception ex) { DALUtils.ErrorRoutine(ex, "DepartmentDAO", "Update:Error"); } return update; }
public Department GetByName(string name) { Department retDep = null; DbContext _ctx; try { _ctx = new DbContext(); var departments = _ctx.Departments; var department = departments.AsQueryable<Department>().Where(dep => dep.DepartmentName == name).FirstOrDefault(); retDep = (Department)department; } catch (Exception ex) { Console.WriteLine("Problem " + ex.Message); } return retDep; }
// Method Name: Update // Purpose: Updates an Employee in the MongoDatabase, and checks for concurrency // Accepts: An Employee Object // Returns: An int public int Update(Employee emp) { int updateOk = -1; try { DbContext ctx = new DbContext(); ctx.Save<Employee>(emp, "employees"); updateOk = 1; } catch(MongoConcurrencyException e) { updateOk = -2; // DALUtils.ErrorRoutine(e, "EmployeeDAO", "Update"); Console.WriteLine(e.Message); } catch(Exception e) { DALUtils.ErrorRoutine(e, "EmployeeDAO", "Update"); } return updateOk; }
public Employee GetBySurname(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) { Console.WriteLine("Problem " + ex.Message); } return retEmp; }
// Method Name: GetById // Purpose: Retrieve an employee by Employee._id // Accepts: An ObjectId // Returns: An Employee Object public Employee GetById(string id) { Employee retEmp = null; DbContext _ctx; ObjectId _id = new ObjectId(id); try { _ctx = new DbContext(); var employees = _ctx.Employees; var employee = employees.AsQueryable<Employee>().Where(emp => emp._id == _id).FirstOrDefault(); retEmp = (Employee)employee; } catch(Exception e) { DALUtils.ErrorRoutine(e, "EmployeeDAO", "GetById"); } return retEmp; }