示例#1
0
        public void ExistingEmployee()
        {
            using (var db = new CompanyDbEntities())
            {
                int employeeId;
                var employee = new Employee();
                Console.WriteLine("Enter Your Name:" + employee.EmployeeName);
                employee.EmployeeName = Console.ReadLine();

                var name = db.Employees.SingleOrDefault(t => t.EmployeeName == employee.EmployeeName);
                employeeId = employee.EmployeeId;

                if (name != null)
                {
                    var employeedetails = db.vEmployees.Where(t => t.EmployeeName == employee.EmployeeName);
                    foreach (var list in employeedetails)
                    {
                        Console.WriteLine("Your Details are as follows:");
                        Console.WriteLine($"Name- {list.EmployeeName}     Project Name - {list.ProjectName}     Business Unit - {list.BusinessUnitName}");
                    }
                }
                else
                {
                    Console.WriteLine("You are not registered");
                    Console.WriteLine("Please register yourself");
                    AddEmployee();
                }
            }
        }
示例#2
0
        public void RemoveProjectManager()
        {
            using (var db = new CompanyDbEntities())
            {
                int projectId;
                var projectmanager = new ProjectManager();
                var project        = new Project();

                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)
                {
                    db.ProjectManagers.Remove(db.ProjectManagers.Single(t => t.ProjectId == projectId));
                    db.SaveChanges();
                    Console.WriteLine("Project manager is successfully removed");
                }
                else
                {
                    Console.WriteLine("There is no such project");
                    Console.WriteLine("Enter valid name");
                }
            }
        }
示例#3
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");
                }
            }
        }
示例#4
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");
                }
            }
        }
示例#5
0
 public void ViewProjectManager()
 {
     using (var db = new CompanyDbEntities())
     {
         var projectmanager = db.vProjectManagers;
         Console.WriteLine("Detail of project with manager");
         foreach (var list in projectmanager)
         {
             Console.WriteLine($"Name- {list.EmployeeName}    Project Name - {list.ProjectName}    Business Unit - {list.BusinessUnitName}");
         }
     }
 }
示例#6
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");
                }
            }
        }
示例#7
0
        public void RemoveBusinessUnit()
        {
            using (var db = new CompanyDbEntities())
            {
                var businessunit = new BusinessUnit();
                Console.WriteLine("Enter name of business unit you want to remove:" + businessunit.BusinessUnitName);
                businessunit.BusinessUnitName = Console.ReadLine();

                var bu = db.BusinessUnits.SingleOrDefault(t => t.BusinessUnitName == businessunit.BusinessUnitName);
                if (bu != null)
                {
                    db.BusinessUnits.Remove(db.BusinessUnits.Single(t => t.BusinessUnitName == businessunit.BusinessUnitName));
                    db.SaveChanges();
                    Console.WriteLine("Business Unit Removed");
                }
                else
                {
                    Console.WriteLine("There is no such unit present");
                }
            }
        }
示例#8
0
        public void RemoveProject()
        {
            using (var db = new CompanyDbEntities())
            {
                var project = new Project();

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

                var p = db.Projects.SingleOrDefault(t => t.ProjectName == project.ProjectName);
                if (p != null)
                {
                    db.Projects.Remove(db.Projects.Single(t => t.ProjectName == project.ProjectName));
                    db.SaveChanges();
                    Console.WriteLine("Project Unit Removed");
                }
                else
                {
                    Console.WriteLine("There is no such project present");
                }
            }
        }
示例#9
0
        public void AddBusinessUnit()
        {
            using (var db = new CompanyDbEntities())
            {
                var businessunit = new BusinessUnit();

                Console.WriteLine("Enter Business Unit Name: " + businessunit.BusinessUnitName);
                businessunit.BusinessUnitName = Console.ReadLine();

                var bu = db.BusinessUnits.SingleOrDefault(t => t.BusinessUnitName == businessunit.BusinessUnitName);
                if (bu == null)
                {
                    db.BusinessUnits.Add(businessunit);
                    db.SaveChanges();
                    Console.WriteLine("Business Unit Added");
                }
                else
                {
                    Console.WriteLine("There is already such unit present");
                }
            }
        }
示例#10
0
        public void AddProject()
        {
            using (var db = new CompanyDbEntities())
            {
                var project = new Project();

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

                var p = db.Projects.SingleOrDefault(t => t.ProjectName == project.ProjectName);
                if (p != null)
                {
                    Console.WriteLine("There is already such project present");
                }
                else
                {
                    var bulist = db.BusinessUnits;
                    {
                        foreach (var bu in bulist)
                        {
                            Console.WriteLine($"List of Business Units - {bu.BusinessUnitId} - {bu.BusinessUnitName}");
                        }
                    }
                    Console.WriteLine($"Enter Business Unit Id from above list:" + project.BusinessUnitId);
                    project.BusinessUnitId = Convert.ToInt32(Console.ReadLine());

                    var bl = db.BusinessUnits.SingleOrDefault(t => t.BusinessUnitId == project.BusinessUnitId);
                    if (bl == null)
                    {
                        Console.WriteLine("There is no such business unit");
                        Console.WriteLine("Please Enter valid details");
                    }
                    db.Projects.Add(project);
                    db.SaveChanges();
                    Console.WriteLine("Project Added");
                }
            }
        }
示例#11
0
        public void AddEmployee()
        {
            using (var db = new CompanyDbEntities())
            {
                var employee = new Employee();
                Console.WriteLine("Enter Your Name: " + employee.EmployeeName);
                employee.EmployeeName = Console.ReadLine();

                var emp = db.Employees.SingleOrDefault(t => t.EmployeeName == employee.EmployeeName);
                if (emp != null)
                {
                    Console.WriteLine("There is already such employee present");
                }
                else
                {
                    var bulist = db.BusinessUnits;
                    {
                        foreach (var bu in bulist)
                        {
                            Console.WriteLine($"List of Business Units - {bu.BusinessUnitId} - {bu.BusinessUnitName}");
                        }
                    }
                    Console.WriteLine($"Enter Business Unit Id from above list:" + employee.BusinessUnitId);
                    employee.BusinessUnitId = Convert.ToInt32(Console.ReadLine());

                    var bl = db.BusinessUnits.SingleOrDefault(t => t.BusinessUnitId == employee.BusinessUnitId);
                    if (bl == null)
                    {
                        Console.WriteLine("There is no such business unit");
                        Console.WriteLine("Please Enter valid details");
                    }
                    db.Employees.Add(employee);
                    db.SaveChanges();
                    Console.WriteLine("Employee Added");
                }
            }
        }
        static void Main(string[] args)
        {
            int choice = 0;

            Console.WriteLine("Welcome To Company Management System");
            var dbContext = new CompanyDbEntities();

            Console.WriteLine("1. Show Business Unit");
            Console.WriteLine("2. Allocate Projects");
            Console.Write("Enter Your Choice :");
            choice = Convert.ToInt32(Console.ReadLine());
            do
            {
                switch (choice)
                {
                case 1:
                    showBusinessUnits();
                    break;

                case 2:
                    showProjects();
                    break;
                }
                Console.Write("Enter Your Choice :");
                choice = Convert.ToInt32(Console.ReadLine());
            } while (choice != 0);

            void showBusinessUnits()
            {
                var businessUnits = new BusinessUnit();

                Console.Write("Enter Unit Name to view Employee in this unit : ");
                businessUnits.BusinessUnitName = Console.ReadLine();

                var unit = dbContext.BusinessUnits.Where(t => t.BusinessUnitName == businessUnits.BusinessUnitName).FirstOrDefault();

                try {
                    showEmployee(unit.BusinessUnitId);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Department invalid");
                }
            }

            void showEmployee(int unitid)
            {
                //     var employee = new Employee();
                var employeeList = dbContext.Employees.Where(t => t.BusinessUnitId == unitid);

                Console.WriteLine("EmpId\tEmpName\tEmp Email Id\tPhone Number\tStatus");
                foreach (var emp in employeeList)
                {
                    Console.WriteLine(emp.EmployeeId + "       " + emp.EmployeeName + "  " + emp.EmployeeEmailId + "  " + emp.EmployeePhoneNumber + " " + emp.EmployeeStatus);
                }
            }

            void showProjects()
            {
                var projectList = dbContext.Projects;

                Console.WriteLine("ProjectId\tProjectName\tProjectDetails ");
                foreach (var project in projectList)
                {
                    Console.WriteLine(project.ProjectId + "\t     " + project.ProjectName + "  " + project.ProjectDetail);
                }

                Console.WriteLine("Enter Project Id to assign employees:");
                var projectId = Convert.ToInt32(Console.ReadLine());

                var employeeList = dbContext.Employees;

                Console.WriteLine("EmpId\tEmpName\tEmp Email Id\tPhone Number\tStatus");
                foreach (var emp in employeeList)
                {
                    Console.WriteLine(emp.EmployeeId + "       " + emp.EmployeeName + "  " + emp.EmployeeEmailId + "  " + emp.EmployeePhoneNumber + " " + emp.EmployeeStatus);
                }
                Console.Write("Enter EmployeeId");
                var empId = Convert.ToInt32(Console.ReadLine());

                allocateEmployee(projectId, empId);
            }

            void allocateEmployee(int projectId, int empId)
            {
                var allocateProject = new AllocateProject();

                //  allocateProject.AllocateProjectId = 1;
                allocateProject.EmployeeId = 1;
                allocateProject.ProjectId  = 1;
                Console.Write("Enter Employee Designation for This Project :");
                allocateProject.Designation = Console.ReadLine();
                using (dbContext)
                {
                    try
                    {
                        dbContext.AllocateProjects.Add(allocateProject);
                        dbContext.SaveChanges();
                        Console.WriteLine("Employee Allocated Successfully");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
        }
示例#13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to our company employee management system");
            var dbEntity = new CompanyDbEntities();

            showDepartment();
            Console.WriteLine("------------------------------------------------------------");
            showProject();

            void showDepartment()
            {
                Console.WriteLine("Enter the department name for which you want to see the employee list");
                var businessUnit = new BusinessUnit();

                businessUnit.BusinessUnitName = Console.ReadLine();

                var db       = new CompanyDbEntities();
                var deptList = db.BusinessUnits.Where(t => t.BusinessUnitName == businessUnit.BusinessUnitName).First();
                var deptId   = deptList.BusinessUnitId;

                showEmployee(deptId);
            }

            void showEmployee(int deptId)
            {
                var employee  = new Employee();
                var dbContext = new CompanyDbEntities();

                Console.WriteLine("All the employees of that department");
                var employeename = dbContext.Employees.Where(t => t.BusinessUnitId == deptId);

                foreach (var employees in employeename)
                {
                    Console.WriteLine(employees.EmployeeId + employees.EmployeeName + employees.Age + employees.Designation + employees.Gender + employees.Designation);
                }
            }

            void showProject()
            {
                var project     = new Project();
                var db1         = new CompanyDbEntities();
                var projectList = db1.Projects;

                Console.WriteLine("Project List is given below");
                foreach (var projects in projectList)
                {
                    Console.WriteLine(projects.ProjectId + projects.ProjectName + projects.ProjectDetail + projects.DeadlineDate);
                }
                Console.WriteLine("Enter the ProjectId for which you want to assign employee");
                Console.WriteLine("--------------------------------------------------------------");
                var projectId = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("--------------------------------------------------------------");

                var employee = new Employee();

                Console.WriteLine("Choose from the employee id from the below list to assign them to any of the project.");
                Console.WriteLine("This list contains the employee names who are not on vacation");
                var emplist = db1.Employees.Where(t => t.EmployeeStatus == "Active");

                foreach (var emp in emplist)
                {
                    Console.WriteLine(emp.EmployeeId + emp.EmployeeName + emp.Age + emp.Designation + emp.Gender + emp.Designation);
                }
                Console.WriteLine("--------------------------------------------------------------");
                Console.WriteLine("Enter the employee id");
                var empId = Convert.ToInt32(Console.ReadLine());

                assignEmployee(projectId, empId);
            }

            void assignEmployee(int projectId, int empId)
            {
                var assign = new AssignEmployee();

                assign.EmployeeId = empId;
                assign.ProjectId  = projectId;
                Console.WriteLine("Enter the designation you want to give to the employee for the given project");
                assign.AssignDesignation = Console.ReadLine();
                using (dbEntity)
                {
                    try
                    {
                        dbEntity.AssignEmployees.Add(assign);
                        dbEntity.SaveChanges();
                        Console.WriteLine("The employee is successfully added to the project");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
        }