// End GetByLastname //Update with Repo public UpdateStatus Update(Employee emp) { UpdateStatus status = UpdateStatus.Failed; HelpdeskRepository repo = new HelpdeskRepository(new DbContext()); try { var builder = Builders <Employee> .Filter; var filter = Builders <Employee> .Filter.Eq("Id", emp.Id) & Builders <Employee> .Filter.Eq("Version", emp.Version); var update = Builders <Employee> .Update .Set("DepartmentId", emp.DepartmentId) .Set("Email", emp.Email) .Set("Firstname", emp.Firstname) .Set("Lastname", emp.Lastname) .Set("Phoneno", emp.Phoneno) .Set("Title", emp.Title) .Set("StaffPicture64", emp.StaffPicture64) .Inc("Version", 1); status = repo.Update(emp.Id.ToString(), filter, update); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "UpdateWithRepo"); } return(status); }
//End UpdateWithRepo //Create - add an Department document to the Departments collection public Department Create(Department dept) { HelpdeskRepository repo = new HelpdeskRepository(new DbContext()); try { dept = repo.Create(dept); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "DepartmentDAO", "Create"); } return(dept); }
//End UpdateWithRepo //Create - add an Problem document to the Problems collection public Problem Create(Problem prob) { HelpdeskRepository repo = new HelpdeskRepository(new DbContext()); try { prob = repo.Create(prob); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "ProblemDAO", "Create"); } return(prob); }
//End UpdateWithRepo //Create - add an Employee document to the employees collection public Employee Create(Employee emp) { HelpdeskRepository repo = new HelpdeskRepository(new DbContext()); try { emp = repo.Create(emp); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "Create"); } return(emp); }
//Delete - returns a long (1 or 0) depending on if the delete was successful public long Delete(string Id) { long deleteFlag = 0; try { deleteFlag = repo.Delete <Department>(Id); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "DepartmentDAO", "Delete"); } return(deleteFlag); }
//GetByID - Similar to GetByLastname, see above. public Department GetById(string Id) { Department dept = null; var builder = Builders <Department> .Filter; try { dept = repo.GetById <Department>(Id); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "DepartmentDAO", "GetById"); } return(dept); }
//GetAll - This one is just going to return a straight List of Department instances public List <Department> GetAll() { List <Department> deptList = new List <Department>(); try { deptList.AddRange(repo.GetAll <Department>().ToList()); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "DepartmentDAO", "GetAll"); } return(deptList); }
//GetByID - Similar to GetByLastname, see above. public Problem GetById(string Id) { Problem prob = null; var builder = Builders <Problem> .Filter; try { prob = repo.GetById <Problem>(Id); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "ProblemDAO", "GetById"); } return(prob); }
//GetAll - This one is just going to return a straight List of Problem instances public List <Problem> GetAll() { List <Problem> probList = new List <Problem>(); try { probList.AddRange(repo.GetAll <Problem>().ToList()); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "ProblemDAO", "GetAll"); } return(probList); }
//GetByID - Similar to GetByLastname, see above. public Employee GetById(string Id) { Employee emp = null; var builder = Builders <Employee> .Filter; try { emp = repo.GetById <Employee>(Id); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "GetById"); } return(emp); }
//GetAll - This one is just going to return a straight List of Employee instances public List <Employee> GetAll() { List <Employee> empList = new List <Employee>(); try { empList.AddRange(repo.GetAll <Employee>().ToList()); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "GetAll"); } return(empList); }
//GetByLastname public Department GetByDepartmentName(string deptName) { Department dept = null; var builder = Builders <Department> .Filter; var filter = builder.Eq("DepartmentName", deptName); try { dept = repo.GetOne <Department>(filter); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "DepartmentDAO", "GetByLastname"); } return(dept); }
//GetByLastname public Problem GetByProblemName(string probName) { Problem prob = null; var builder = Builders <Problem> .Filter; var filter = builder.Eq("Description", probName); try { prob = repo.GetOne <Problem>(filter); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "ProblemDAO", "GetByDescription"); } return(prob); }
//GetByLastname public Employee GetByLastname(string name) { Employee emp = null; var builder = Builders <Employee> .Filter; var filter = builder.Eq("Lastname", name); try { emp = repo.GetOne <Employee>(filter); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "EmployeeDAO", "GetByLastname"); } return(emp); }
// End GetByLastname //Update with Repo public UpdateStatus Update(Department dept) { UpdateStatus status = UpdateStatus.Failed; try { var builder = Builders <Department> .Filter; var filter = Builders <Department> .Filter.Eq("Id", dept.Id) & Builders <Department> .Filter.Eq("Version", dept.Version); var update = Builders <Department> .Update .Set("DepartmentName", dept.DepartmentName) .Inc("Version", 1); status = repo.Update(dept.Id.ToString(), filter, update); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "DepartmentDAO", "Update"); } return(status); }
// End GetByLastname //Update with Repo public UpdateStatus Update(Problem prob) { UpdateStatus status = UpdateStatus.Failed; try { var builder = Builders <Problem> .Filter; var filter = Builders <Problem> .Filter.Eq("Id", prob.Id) & Builders <Problem> .Filter.Eq("Version", prob.Version); var update = Builders <Problem> .Update .Set("Description", prob.Description) .Inc("Version", 1); status = repo.Update(prob.Id.ToString(), filter, update); } catch (Exception ex) { DALUtilsV2.ErrorRoutine(ex, "ProblemDAO", "Update"); } return(status); }