Пример #1
0
        public static List <ProjectService> FindProjects(string key)
        {
            List <ProjectService> projects = null;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                var query = from b in db.Projects
                            where b.Name.StartsWith(key)
                            select b;

                if (query.Count() > 0)
                {
                    projects = new List <ProjectService>();

                    foreach (var item in query)
                    {
                        projects.Add(new ProjectService
                                         (item.ProjectId,
                                         item.Name,
                                         item.Price));
                    }
                }
            }

            return(projects);
        }
Пример #2
0
        public static List <PositionService> FindPositions(string key)
        {
            List <PositionService> positions = null;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                var query = from b in db.Positions
                            where b.Name.StartsWith(key)
                            select b;

                if (query.Count() > 0)
                {
                    positions = new List <PositionService>();

                    foreach (var item in query)
                    {
                        positions.Add(new PositionService
                                          (item.PositionID,
                                          item.Name,
                                          item.Hours,
                                          item.Payment));
                    }
                }
            }

            return(positions);
        }
Пример #3
0
        public static List <EmployeeService> ExtendedFindEmployees(string key, int keyNumber)
        {
            List <EmployeeService> employees = null;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                var query = from b in db.Employees
                            where b.Name.StartsWith(key) ||
                            b.Surname.StartsWith(key) ||
                            b.AccountNumber.Equals(keyNumber) ||
                            b.Experience.Equals(keyNumber)
                            select b;

                if (query.Count() > 0)
                {
                    employees = new List <EmployeeService>();

                    foreach (var item in query)
                    {
                        employees.Add(new EmployeeService
                                          (item.Id,
                                          item.Name,
                                          item.Surname,
                                          item.AccountNumber,
                                          item.Experience,
                                          item.Department.Name,
                                          item.Position.Name));
                    }
                }
            }

            return(employees);
        }
Пример #4
0
        public static List <DepartmentService> FindDepartments(string key)
        {
            List <DepartmentService> departments = null;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                var query = from b in db.Departments
                            where b.Name.StartsWith(key)
                            select b;

                if (query.Count() > 0)
                {
                    departments = new List <DepartmentService>();

                    foreach (var item in query)
                    {
                        departments.Add(new DepartmentService
                                            (item.DepartmentID,
                                            item.Name));
                    }
                }
            }

            return(departments);
        }
        public static List <EmployeeService> GetByPayment()
        {
            List <EmployeeService> employees = new List <EmployeeService>();

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                var query = from b in db.Employees
                            orderby b.Position.Payment
                            select b;

                foreach (var item in query)
                {
                    EmployeeService toAdd = new EmployeeService
                                                (item.Id,
                                                item.Name,
                                                item.Surname,
                                                item.AccountNumber,
                                                item.Experience,
                                                item.Department.Name,
                                                item.Position.Name);

                    employees.Add(toAdd);
                }
            }
            return(employees);
        }
Пример #6
0
        public static EmployeeService GetTopEmployee(int positionId)
        {
            EmployeeService employee = null;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                if (db.Positions.Find(positionId) != null && db.Positions.Find(positionId).Employees.Count != 0)
                {
                    List <Employee>        dbEmployees = db.Positions.Find(positionId).Employees;
                    List <EmployeeService> employees   = new List <EmployeeService>();

                    foreach (var item in dbEmployees)
                    {
                        EmployeeService toAdd = new EmployeeService(
                            item.Id,
                            item.Name,
                            item.Surname,
                            item.AccountNumber,
                            item.Experience,
                            item.Department.Name,
                            item.Position.Name);

                        employees.Add(toAdd);
                    }

                    employee = employees.OrderBy(o => o.Experience / o.SumProjectPrice).ToList()[0];
                }
            }

            return(employee);
        }
Пример #7
0
        public static List <EmployeeService> GetEmployeeList(int id)
        {
            List <EmployeeService> employees = new List <EmployeeService>();

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                if (db.Departments.Find(id) != null)
                {
                    Department find = db.Departments.Find(id);

                    List <Employee> findEmployees = db.Departments.Find(id).Employees;


                    foreach (Employee item in findEmployees)
                    {
                        EmployeeService toAdd = new EmployeeService(
                            item.Id,
                            item.Name,
                            item.Surname,
                            item.AccountNumber,
                            item.Experience,
                            item.Department.Name,
                            item.Position.Name);

                        employees.Add(toAdd);
                    }
                }
            }
            return(employees);
        }
Пример #8
0
 public static void ChangeHours(int positionId, double hours)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Positions.Find(positionId) != null)
         {
             db.Positions.Find(positionId).Hours = hours;
         }
     }
 }
Пример #9
0
 public static void ChangeName(int positionId, string name)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Positions.Find(positionId) != null)
         {
             db.Positions.Find(positionId).Name = name;
         }
     }
 }
Пример #10
0
 public static void ChangePayment(int positionId, double payment)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Positions.Find(positionId) != null)
         {
             db.Positions.Find(positionId).Payment = payment;
         }
     }
 }
 public static void ChangeAccountNumber(int id, int accountNummber)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Employees.Find(id) != null)
         {
             db.Employees.Find(id).AccountNumber = accountNummber;
             db.SaveChanges();
         }
     }
 }
 public static void ChangePosition(int id, int positionId)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Employees.Find(id) != null)
         {
             db.Employees.Find(id).Position = db.Positions.Find(positionId);
             db.SaveChanges();
         }
     }
 }
 public static void ChangeDepartment(int id, int departmentId)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Employees.Find(id) != null)
         {
             db.Employees.Find(id).Department = db.Departments.Find(departmentId);
             db.SaveChanges();
         }
     }
 }
 public static void ChangeExperience(int id, int experience)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Employees.Find(id) != null)
         {
             db.Employees.Find(id).Experience = experience;
             db.SaveChanges();
         }
     }
 }
 public static void ChangeSurname(int id, string surname)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Employees.Find(id) != null)
         {
             db.Employees.Find(id).Surname = surname;
             db.SaveChanges();
         }
     }
 }
Пример #16
0
 public static void ChangeDepartment(int departmentId, string name)
 {
     using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
     {
         if (db.Departments.Find(departmentId) != null)
         {
             db.Departments.Find(departmentId).Name = name;
             db.SaveChanges();
         }
     }
 }
Пример #17
0
        public static void AddDepartment(string name)
        {
            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                Department department = new Department {
                    Name = name
                };

                db.Departments.Add(department);
                db.SaveChanges();
            }
        }
Пример #18
0
        public static void AddPosition(string name, double hours, double payment)
        {
            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                Position position = new Position {
                    Name = name, Hours = hours, Payment = payment
                };

                db.Positions.Add(position);
                db.SaveChanges();
            }
        }
Пример #19
0
        public static void AddProject(string name, int price, int employeeId)
        {
            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                Project project = new Project
                {
                    Name     = name,
                    Price    = price,
                    Employee = db.Employees.Find(employeeId)
                };

                db.Projects.Add(project);
                db.SaveChanges();
            }
        }
Пример #20
0
        public static bool DeleteDepartments(int departmentId)
        {
            bool flag = false;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                if (db.Departments.Find(departmentId) != null)
                {
                    db.Departments.Remove(db.Departments.Find(departmentId));
                    db.SaveChanges();

                    flag = true;
                }
            }
            return(flag);
        }
Пример #21
0
        public static DepartmentService GetDepartment(int departmentId)
        {
            DepartmentService department = null;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                if (db.Departments.Find(departmentId) != null)
                {
                    Department find = db.Departments.Find(departmentId);


                    department = new DepartmentService(find.DepartmentID, find.Name);
                }
            }

            return(department);
        }
        public static void AddEmployee(string name, string surname, int accountnumber,
                                       int experience, int idDepartment, int idPosition)
        {
            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                Employee employee = new Employee
                {
                    Name          = name,
                    Surname       = surname,
                    AccountNumber = accountnumber,
                    Experience    = experience,
                    Department    = db.Departments.Find(idDepartment),
                    Position      = db.Positions.Find(idPosition)
                };

                db.Employees.Add(employee);
                db.SaveChanges();
            }
        }
        public static bool DeleteEmployee(int id)
        {
            bool flag = false;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                if (db.Employees.Find(id) != null)
                {
                    foreach (var item in db.Employees.Find(id).Projects)
                    {
                        item.Employee = null;
                    }
                    db.Employees.Remove(db.Employees.Find(id));
                    db.SaveChanges();

                    flag = true;
                }
            }
            return(flag);
        }
Пример #24
0
        public static List <DepartmentService> GetDepartments()
        {
            List <DepartmentService> departments = new List <DepartmentService>();

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                var query = from b in db.Departments
                            select b;

                foreach (var item in query)
                {
                    DepartmentService toAdd = new DepartmentService(
                        item.DepartmentID,
                        item.Name);

                    departments.Add(toAdd);
                }
            }

            return(departments);
        }
        public static List <ProjectService> GetEmployeeProjects(int id)
        {
            List <ProjectService> projects = new List <ProjectService>();

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                if (db.Employees.Find(id) != null)
                {
                    List <Project> dbProjects = db.Employees.Find(id).Projects;

                    foreach (Project item in dbProjects)
                    {
                        projects.Add(new ProjectService
                                         (item.ProjectId,
                                         item.Name,
                                         item.Price));
                    }
                }
            }
            return(projects);
        }
Пример #26
0
        public static List <PositionService> GetPositions()
        {
            List <PositionService> positions = new List <PositionService>();

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                var query = from b in db.Positions
                            select b;

                foreach (var item in query)
                {
                    PositionService toAdd = new PositionService(
                        item.PositionID,
                        item.Name,
                        item.Hours,
                        item.Payment);

                    positions.Add(toAdd);
                }
            }

            return(positions);
        }
        public static EmployeeService GetEmployee(int id)
        {
            EmployeeService employee = null;
            Employee        find     = null;

            using (HumanResourcesDepartmentContext db = new HumanResourcesDepartmentContext())
            {
                if (db.Employees.Find(id) != null)
                {
                    find = db.Employees.Find(id);

                    employee = new EmployeeService(
                        find.Id,
                        find.Name,
                        find.Surname,
                        find.AccountNumber,
                        find.Experience,
                        find.Department.Name,
                        find.Position.Name);
                }
            }

            return(employee);
        }