Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
 //  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;
 }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
 //  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;
 }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
        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;
        }
Ejemplo n.º 11
0
        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;
        }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 13
0
        /// <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;
        }
Ejemplo n.º 14
0
        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;
        }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 16
0
        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;
        }
Ejemplo n.º 17
0
        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;
        }
Ejemplo n.º 18
0
        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;
        }
Ejemplo n.º 19
0
 //  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;
 }
Ejemplo n.º 20
0
        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;
        }
Ejemplo n.º 21
0
 //  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;
 }