Ejemplo n.º 1
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");
                }
            }
        }
Ejemplo n.º 2
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");
                }
            }
        }
Ejemplo n.º 3
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }