Exemple #1
0
        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;
        }
Exemple #2
0
        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;
        }
Exemple #3
0
        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;
        }
Exemple #4
0
        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;
        }
Exemple #5
0
        /// <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;
        }
Exemple #6
0
        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;
        }
Exemple #8
0
        /// <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;
        }