Exemplo n.º 1
0
        public void RemoveEmployeeFromProject()
        {
            using (var db = new CompanyDbEntities())
            {
                int employeeId;

                var projemp = new Project_Employees();
                var emp     = new Employee();

                Console.WriteLine("Enter Employee Name:" + emp.EmployeeName);
                emp.EmployeeName = Console.ReadLine();
                var en = db.Employees.SingleOrDefault(t => t.EmployeeName == emp.EmployeeName);
                employeeId         = en.EmployeeId;
                projemp.EmployeeId = employeeId;

                if (en != null)
                {
                    db.Project_Employees.Remove(db.Project_Employees.Single(t => t.EmployeeId == employeeId));
                    db.SaveChanges();
                    Console.WriteLine("Employee removed from assigned project");
                }
                else
                {
                    Console.WriteLine("No project is assign to employee");
                }
            }
        }
Exemplo n.º 2
0
        public void AssignProjectManager()
        {
            using (var db = new CompanyDbEntities())
            {
                int projectId;
                int projectemployeeId;
                int employeeId;

                var projectmanager  = new ProjectManager();
                var project         = new Project();
                var projectemployee = new Project_Employees();

                Console.WriteLine("Enter Project Name: " + project.ProjectName);
                project.ProjectName = Console.ReadLine();

                var pn = db.Projects.SingleOrDefault(t => t.ProjectName == project.ProjectName);
                projectId = pn.ProjectId;
                projectmanager.ProjectId = projectId;

                if (pn != null)
                {
                    var emp = new Employee();
                    Console.WriteLine("Enter employee name: " + emp.EmployeeName);
                    emp.EmployeeName = Console.ReadLine();

                    var en = db.Employees.SingleOrDefault(t => t.EmployeeName == emp.EmployeeName);
                    employeeId = en.EmployeeId;

                    if (en != null)
                    {
                        var e = db.Project_Employees.SingleOrDefault(t => t.EmployeeId == employeeId);
                        projectemployeeId = e.ProjectEmployeeId;
                        if (e != null)
                        {
                            projectmanager.ProjectEmployeeId = projectemployeeId;
                            db.ProjectManagers.Add(projectmanager);
                            db.SaveChanges();
                            Console.WriteLine("Project manager is successfully assigned");
                        }
                        else
                        {
                            Console.WriteLine("No project is assign to this employee");
                        }
                    }
                    else
                    {
                        Console.WriteLine("There is no such employee!");
                    }
                }
                else
                {
                    Console.WriteLine("There is no such project");
                    Console.WriteLine("Enter valid name");
                }
            }
        }
Exemplo n.º 3
0
        public void AssignProject()
        {
            using (var db = new CompanyDbEntities())
            {
                int projectId;
                int employeeId;

                var projemp = new Project_Employees();
                var project = new Project();
                var emp     = new Employee();

                Console.WriteLine("Enter Project Name: " + project.ProjectName);
                project.ProjectName = Console.ReadLine();

                var pn = db.Projects.SingleOrDefault(t => t.ProjectName == project.ProjectName);
                projectId         = pn.ProjectId;
                projemp.ProjectId = projectId;

                if (pn != null)
                {
                    Console.WriteLine("Enter Employee Name:" + emp.EmployeeName);
                    emp.EmployeeName = Console.ReadLine();

                    var en = db.Employees.SingleOrDefault(t => t.EmployeeName == emp.EmployeeName);
                    employeeId         = en.EmployeeId;
                    projemp.EmployeeId = employeeId;

                    if (en != null)
                    {
                        db.Project_Employees.Add(projemp);
                        db.SaveChanges();
                        Console.WriteLine("Project assigned to employee");
                    }
                    else
                    {
                        Console.WriteLine("There is no such employee");
                    }
                }
                else
                {
                    Console.WriteLine("There is no such project");
                    Console.WriteLine("Enter valid name");
                }
            }
        }