Example #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool DeleteDepartment(int ID)
        {
            var departRepository = new DepartmentRepository();

            return(departRepository.DeleteDepartment(ID));
        }
Example #2
0
 public int DeleteDepartment(DepartmentModel department)
 {
     return(_departmentRepository.DeleteDepartment(department));
 }
Example #3
0
        static void Main(string[] args)
        {
            //Authored by & stolen from James Nitz
            //For educational purposes only

            //Setting a new instance of the employee repository and dept repo to a variable. Remeber to use the using statement at the top!
            var repo     = new EmployeeRepository();
            var deptRepo = new DepartmentRepository();
            //That both classes has method that gets all employees. Use it and store all them employees in a var.


            var employeeWithId2 = repo.GetEmployeeById(2);


            while (true)
            {
                var departments = deptRepo.GetAllDepartments();
                var employees   = repo.GetAllEmployeesWithDepartment();
                Console.WriteLine("Welcome to muh Database!!");
                Console.WriteLine("Press 1 for Departments");
                Console.WriteLine("Press 2 for Employee");
                Console.WriteLine("Press 3 for a full report");
                Console.WriteLine("Press 4 to get outta here");

                string option = Console.ReadLine();

                if (option == "1")
                {
                    Console.Clear();
                    Console.WriteLine("---DEPARTMENTS---");
                    Console.WriteLine("Press 1 to add a Department");
                    Console.WriteLine("Press 2 to add a Delete");
                    Console.WriteLine("Press 3 to return");
                    string deptOption = Console.ReadLine();

                    switch (Int32.Parse(deptOption))
                    {
                    case 1:
                        Console.Clear();
                        Console.WriteLine("Name of Department?");
                        var        deptNameInput = Console.ReadLine();
                        Department newDepartment = new Department()
                        {
                            DeptName = deptNameInput
                        };
                        deptRepo.AddDepartment(newDepartment);
                        break;

                    case 2:
                        Console.Clear();
                        Console.WriteLine("Delete which Department?");
                        for (var i = 0; i < departments.Count; i++)
                        {
                            Console.WriteLine($"{departments[i].Id}  {departments[i].DeptName}");
                        }
                        var deleteDeptInput = Int32.Parse(Console.ReadLine());
                        try
                        {
                            deptRepo.DeleteDepartment(deleteDeptInput);
                            break;
                        }
                        catch
                        {
                            Console.Clear();
                            Console.WriteLine("Cannot delete department with working employees.");
                            Console.WriteLine("Please fire or transfer:");
                            Console.WriteLine("");
                            foreach (var employee in employees)
                            {
                                if (employee.DepartmentId == deleteDeptInput)
                                {
                                    Console.WriteLine($"{employee.FirstName} {employee.LastName}");
                                }
                            }
                            Console.WriteLine("Press enter to return");
                            Console.ReadLine();
                            break;
                        }

                    case 3:
                        break;

                    default:
                        break;
                    }
                }
                else if (option == "2")
                {
                    Console.Clear();
                    Console.WriteLine("---EMPLOYEES---");
                    Console.WriteLine("Press 1 to add an employee");
                    Console.WriteLine("Press 2 to Fire an Employee");
                    Console.WriteLine("Press 3 to update an employee");
                    Console.WriteLine("Press 4 to return");
                    string empOption = Console.ReadLine();

                    switch (Int32.Parse(empOption))
                    {
                    case 1:
                        Console.Clear();
                        Console.WriteLine("First name of Employee?");
                        var employeeFirstNameInput = Console.ReadLine();
                        Console.WriteLine("Last Name of Employee?");
                        var employeeLastNameInput = Console.ReadLine();
                        Console.WriteLine("Which Department do they work in?");
                        foreach (var dept in departments)
                        {
                            Console.WriteLine($"{dept.Id} {dept.DeptName}");
                        }
                        var employeeDeptChoice = Console.ReadLine();
                        var selectedDept       = departments.Where(dept => int.Parse(employeeDeptChoice) == dept.Id).FirstOrDefault();

                        Employee newEmployee = new Employee()
                        {
                            FirstName = employeeFirstNameInput, LastName = employeeLastNameInput, DepartmentId = selectedDept.Id
                        };
                        repo.AddEmployee(newEmployee);
                        break;

                    case 2:
                        Console.Clear();
                        Console.WriteLine("Fire which Employee?");
                        for (var i = 0; i < employees.Count; i++)
                        {
                            Console.WriteLine($"{employees[i].Id}  {employees[i].FirstName} {employees[i].LastName}");
                        }
                        var deleteEmployeeInput = Int32.Parse(Console.ReadLine());
                        repo.DeleteEmployee(deleteEmployeeInput);
                        break;

                    case 3:
                        Console.Clear();
                        Console.WriteLine("Who you want to update?");
                        for (var i = 0; i < employees.Count; i++)
                        {
                            Console.WriteLine($"{employees[i].Id}  {employees[i].FirstName} {employees[i].LastName}");
                        }
                        var updateEmployeeInput = Int32.Parse(Console.ReadLine());
                        var selectedEmployee    = repo.GetEmployeeById(updateEmployeeInput);
                        Console.Clear();
                        Console.WriteLine($"{selectedEmployee.FirstName} {selectedEmployee.LastName} who works in {selectedEmployee.Department.DeptName}");
                        Console.WriteLine("");
                        Console.WriteLine("What would you like to update?");
                        Console.WriteLine("1. Name");
                        Console.WriteLine("2. Department");
                        var selectedUpdateInput = Console.ReadLine();
                        switch (Int32.Parse(selectedUpdateInput))
                        {
                        case 1:
                            Console.WriteLine("Enter in new first name?");
                            var newFirstName = Console.ReadLine();
                            Console.WriteLine("Enter in new last name?");
                            var newLastName = Console.ReadLine();
                            selectedEmployee.FirstName = newFirstName;
                            selectedEmployee.LastName  = newLastName;
                            repo.UpdateEmployee(selectedEmployee.Id, selectedEmployee);
                            break;

                        case 2:
                            Console.WriteLine("What department do they work in now?");
                            for (var i = 0; i < departments.Count; i++)
                            {
                                Console.WriteLine($"{departments[i].Id}  {departments[i].DeptName}");
                            }
                            var selectedDeptInput = Int32.Parse(Console.ReadLine());

                            var newDept = departments.FirstOrDefault(dept => dept.Id == selectedDeptInput);
                            selectedEmployee.DepartmentId = newDept.Id;
                            repo.UpdateEmployee(selectedEmployee.Id, selectedEmployee);
                            break;

                        default:
                            break;
                        }



                        break;

                    case 4:
                        break;

                    default:
                        break;
                    }
                }
                else if (option == "3")
                {
                    Console.Clear();
                    Console.WriteLine("------------------");
                    foreach (var dept in departments)
                    {
                        Console.WriteLine($"{dept.DeptName} has the following employees:");
                        foreach (var employee in employees)
                        {
                            if (employee.DepartmentId == dept.Id)
                            {
                                Console.WriteLine($"{employee.FirstName} {employee.LastName}");
                            }
                        }
                    }
                    Console.WriteLine("------------------");
                }
                else
                {
                    Console.WriteLine("See ya Later");
                    break;
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            //Department
            var departmentRepo = new DepartmentRepository();
            var allDepartments = departmentRepo.GetAllDepartments();

            Console.WriteLine("All Departments");
            Console.WriteLine("---------------");
            foreach (var dept in allDepartments)
            {
                Console.WriteLine(dept.DepartmentName);
            }

            var hardCodedId      = 2;
            var departmentWithId = departmentRepo.GetDepartmentById(hardCodedId);

            Console.WriteLine("---------------");
            Console.WriteLine($"Department with id {hardCodedId} is {departmentWithId.DepartmentName}");
            Console.WriteLine("---------------");

            //Employee List
            var employeeRepo = new EmployeeRepository();
            var allEmployee  = employeeRepo.GetAllEmployees();

            Console.WriteLine("All Employees");
            Console.WriteLine("---------------");
            foreach (var employee in allEmployee)
            {
                Console.WriteLine($"{employee.FirstName} {employee.LastName}");
            }

            var hardCodedEmployeeId = 2;
            var employeeWithId      = employeeRepo.GetEmployeeById(hardCodedEmployeeId);

            Console.WriteLine("---------------");
            Console.WriteLine($"Department with id {hardCodedEmployeeId} is {employeeWithId.FirstName} {employeeWithId.LastName}");

            //Employee with Department

            var allEmployeeRepo           = new EmployeeRepository();
            var allEmployeeWithDepartment = allEmployeeRepo.GetAllEmployeesWithDepartment();

            Console.WriteLine("All Employees");
            Console.WriteLine("---------------");
            foreach (var employee in allEmployeeWithDepartment)
            {
                Console.WriteLine($"{employee.FirstName} {employee.LastName} works in {employee.EmployeeDepartment}");
            }

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

            //Add Department

            var legal = new Department();

            Console.WriteLine("What department do you like to add?");
            legal.DepartmentName = Console.ReadLine();
            departmentRepo.AddDepartment(legal);
            //Update Department
            Console.WriteLine("What Department (ID) would you like to update?");
            var departmentToUpdate = Int32.Parse(Console.ReadLine());

            Console.WriteLine("What should the new department name be called?");
            var newDepartmentName = Console.ReadLine();

            departmentRepo.UpdateDepartment(departmentToUpdate, new Department {
                DepartmentName = newDepartmentName
            });

            //Delete Department
            Console.WriteLine("What department do you want to delete?");
            var deleteDept = int.Parse(Console.ReadLine());

            departmentRepo.DeleteDepartment(deleteDept);

            Console.WriteLine("--------------------");
            //Add Employee
            var newEmployee = new Employee();

            Console.WriteLine("What is your first name?");
            newEmployee.FirstName = Console.ReadLine();
            Console.WriteLine("What is your last name?");
            newEmployee.LastName = Console.ReadLine();
            Console.WriteLine("What department do you want to work?");
            newEmployee.DepartmentId = Int32.Parse(Console.ReadLine());

            employeeRepo.AddEmployee(newEmployee);

            //Update Employee

            Console.WriteLine("Which Employee (ID) would you like to update?");
            var employeeToUpdate = Int32.Parse(Console.ReadLine());

            var updateEmployee = new Employee();

            Console.WriteLine("What is your first name?");
            updateEmployee.FirstName = Console.ReadLine();
            Console.WriteLine("What is your last name?");
            updateEmployee.LastName = Console.ReadLine();
            Console.WriteLine("What department do you want to work?");
            updateEmployee.DepartmentId = Int32.Parse(Console.ReadLine());

            employeeRepo.UpdateEmployee(employeeToUpdate, updateEmployee);

            //Delete Employee
            Console.WriteLine("Which employee do you want to delete?");
            var deleteEmp = int.Parse(Console.ReadLine());

            employeeRepo.DeleteEmployee(deleteEmp);
        }
Example #5
0
 public void DeleteDepartment(int DepartmentId)
 {
     repository.DeleteDepartment(DepartmentId);
 }