static void Main(string[] args) { DepartmentRepository departmentRepo = new DepartmentRepository(); Console.WriteLine("Getting All Departments:"); Console.WriteLine(); List <Department> allDepartments = departmentRepo.GetAllDepartments(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id} {dept.DeptName}"); } Console.WriteLine("----------------------------"); Console.WriteLine("Getting Department with Id 1"); Department singleDepartment = departmentRepo.GetDepartmentById(1); Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}"); Department legalDept = new Department { DeptName = "Legal" }; departmentRepo.AddDepartment(legalDept); Console.WriteLine("-------------------------------"); Console.WriteLine("Added the new Legal Department!"); departmentRepo.UpdateDepartment(1, new Department() { DeptName = "New Department" }); Console.WriteLine("Here's your updated department:"); Console.WriteLine(departmentRepo.GetDepartmentById(1).DeptName); Console.WriteLine("Now let's delete a department."); departmentRepo.DeleteDepartment(4); List <Department> newDeps = departmentRepo.GetAllDepartments(); foreach (Department dep in newDeps) { Console.WriteLine(dep.DeptName); } Console.ReadLine(); }
static void Main(string[] args) { DepartmentRepository departmentRepo = new DepartmentRepository(); Console.WriteLine("Getting All Departments:"); Console.WriteLine(); List <Department> allDepartments = departmentRepo.GetAllDepartments(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id} {dept.DeptName}"); } }
public static void CollectInput() { Console.Clear(); while (true) { Console.WriteLine("Please enter the id of the department you wish to update"); Console.Write("> "); string response = Console.ReadLine(); int id = Int32.Parse(response); DepartmentRepository departments = new DepartmentRepository(); var foundDepartment = departments.GetDepartmentById(id); Console.Clear(); Console.WriteLine($"{foundDepartment.Id}: {foundDepartment.DeptName}"); Console.WriteLine(); Console.WriteLine("Please enter a new name for the department"); Console.Write(" >"); string deptName = Console.ReadLine(); Department newDepartment = new Department { DeptName = deptName }; departments.UpdateDepartment(id, newDepartment); var updatedDepartment = departments.GetDepartmentById(id); Console.Clear(); Console.WriteLine("Updated department:"); Console.WriteLine($"{updatedDepartment.Id}: {updatedDepartment.DeptName}"); Console.WriteLine($"Press any key to return to the previous menu"); Console.ReadLine(); Console.Clear(); break; } }
public static void CollectInput() { Console.Clear(); while (true) { Console.WriteLine("Please enter the id of the department you wish to delete"); Console.Write("> "); string response = Console.ReadLine(); int id = Int32.Parse(response); DepartmentRepository departments = new DepartmentRepository(); var foundDepartment = departments.GetDepartmentById(id); Console.Clear(); Console.WriteLine($"{foundDepartment.Id}: {foundDepartment.DeptName}"); Console.WriteLine(); Console.WriteLine("Are you sure you wish to delete? y/n"); Console.Write(" >"); string choice = Console.ReadLine(); if (choice == "y") { departments.DeleteDepartment(id); Console.WriteLine(); Console.WriteLine("Department deleted"); Console.WriteLine(); Console.WriteLine($"Press any key to return to the previous menu"); Console.ReadLine(); Console.Clear(); break; } else if (choice == "n") { Console.Clear(); break; } } }
public static void ListDepartments() { Console.Clear(); while (true) { DepartmentRepository departmentRepo = new DepartmentRepository(); Console.WriteLine("All Departments:"); System.Collections.Generic.List <Department> allDepartments = departmentRepo.GetAllDepartments(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id} {dept.DeptName}"); } Console.WriteLine(); Console.WriteLine($"Press any key to return to the previous menu"); Console.ReadLine(); Console.Clear(); break; } }
static void Main(string[] args) { DepartmentRepository departmentRepo = new DepartmentRepository(); EmployeeRepository employeeRepo = new EmployeeRepository(); Console.WriteLine("Getting All Departments:"); Console.WriteLine(); List <Department> allDepartments = departmentRepo.GetAllDepartments(); List <Employee> allEmployees = employeeRepo.GetAllEmployees(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id}.) {dept.DeptName}"); } Console.WriteLine("----------------------------"); Console.WriteLine("Getting Department with Id 1"); Department singleDepartment = departmentRepo.GetDepartmentById(1); Console.WriteLine($"{singleDepartment.Id}.) {singleDepartment.DeptName}"); Console.WriteLine("CREATE"); Console.WriteLine("What's the name of the new Department?"); var newDeptName = Console.ReadLine(); Department newDept = new Department { DeptName = newDeptName }; departmentRepo.AddDepartment(newDept); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new {newDept.DeptName} Department!"); Console.WriteLine("----------------------------"); Console.WriteLine("UPDATE"); Console.WriteLine("which Department (use number)?"); var updatedDepartments = departmentRepo.GetAllDepartments(); foreach (Department dept in updatedDepartments) { Console.WriteLine($"{dept.Id}.) {dept.DeptName}"); } var updatedDepartmentId = int.Parse(Console.ReadLine()); Department departmentToUpdate = departmentRepo.GetDepartmentById(updatedDepartmentId); Console.WriteLine($"Update {departmentToUpdate.DeptName} department Name."); departmentToUpdate.DeptName = Console.ReadLine(); departmentRepo.UpdateDepartment(updatedDepartmentId, departmentToUpdate); Console.WriteLine("----------------------------"); Console.WriteLine("DELETE"); Console.WriteLine("which Department (use number)?"); foreach (Department dept in updatedDepartments) { Console.WriteLine($"{dept.Id}.) {dept.DeptName}"); } var deleteDepartmentId = int.Parse(Console.ReadLine()); Department departmentToDelete = departmentRepo.GetDepartmentById(deleteDepartmentId); Console.WriteLine($"Deleting {departmentToDelete.DeptName}"); departmentRepo.DeleteDepartment(deleteDepartmentId); Console.WriteLine("Getting all Employees"); foreach (Employee emp in allEmployees) { Console.WriteLine($"{emp.Id}.) {emp.FirstName} {emp.LastName}"); } Console.WriteLine("CREATE"); Console.WriteLine("What is their First Name?"); var newEmployeeFirstName = Console.ReadLine(); Console.WriteLine("what is their Last Name?"); var newEmployeeLastName = Console.ReadLine(); Console.WriteLine("Which department do they work in?"); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id}.) {dept.DeptName}"); } var newEmployeeDepartmentId = int.Parse(Console.ReadLine()); Employee newEmployee = new Employee { FirstName = newEmployeeFirstName, LastName = newEmployeeLastName, DepartmentId = newEmployeeDepartmentId }; employeeRepo.AddEmployee(newEmployee); Console.WriteLine("----------------------------"); Console.WriteLine("UPDATE"); Console.WriteLine("which Employee (use number)?"); foreach (Employee emp in allEmployees) { Console.WriteLine($"{emp.Id}.) {emp.FirstName} {emp.LastName}"); } var updatedEmployeeId = int.Parse(Console.ReadLine()); Employee employeeToUpdate = employeeRepo.GetEmployeeById(updatedEmployeeId); Console.WriteLine($"Update {employeeToUpdate.FirstName} {employeeToUpdate.LastName} first name."); employeeToUpdate.FirstName = Console.ReadLine(); Console.WriteLine($"Update {employeeToUpdate.FirstName} {employeeToUpdate.LastName} last name."); employeeToUpdate.LastName = Console.ReadLine(); Console.WriteLine($"Update {employeeToUpdate.FirstName} {employeeToUpdate.LastName}'s department."); employeeToUpdate.DepartmentId = int.Parse(Console.ReadLine()); employeeRepo.UpdateEmployee(updatedEmployeeId, employeeToUpdate); Console.WriteLine("DELETE"); Console.WriteLine("which employee (use number)?"); List <Employee> updatedAllEmployees = employeeRepo.GetAllEmployees(); foreach (Employee emp in updatedAllEmployees) { Console.WriteLine($"{emp.Id}.) {emp.FirstName} {emp.LastName}"); } var deleteEmployeeId = int.Parse(Console.ReadLine()); Employee employeeToDelete = employeeRepo.GetEmployeeById(deleteEmployeeId); Console.WriteLine($"Deleting {employeeToDelete.FirstName} {employeeToDelete.LastName}"); employeeRepo.DeleteEmployee(deleteEmployeeId); }
static void Main(string[] args) { DepartmentRepository departmentRepo = new DepartmentRepository(); Console.WriteLine("Getting All Departments:"); Console.WriteLine(); List <Department> allDepartments = departmentRepo.GetAllDepartments(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id} {dept.DeptName}"); } Console.WriteLine("----------------------------"); Console.WriteLine("Getting Department with Id 1"); Department singleDepartment = departmentRepo.GetDepartmentById(1); Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}"); //Department legalDept = new Department //{ // DeptName = "Legal" //}; //departmentRepo.AddDepartment(legalDept); //Console.WriteLine("-------------------------------"); //Console.WriteLine("Added the new Legal Department!"); //departmentRepo.UpdateDepartment(1, new Department() { DeptName = "New Department" }); //Console.WriteLine("Here's your updated department:"); //Console.WriteLine(departmentRepo.GetDepartmentById(1).DeptName); //Console.WriteLine("Now let's delete a department."); //departmentRepo.DeleteDepartment(4); //List<Department> newDeps = departmentRepo.GetAllDepartments(); //foreach (Department dep in newDeps) //{ // Console.WriteLine(dep.DeptName); //} //Console.ReadLine(); EmployeeRepository employeeRepo = new EmployeeRepository(); Console.WriteLine("Getting all Employees:"); Console.WriteLine(); List <Employee> allEmployees = employeeRepo.GetEmployees(); foreach (Employee empl in allEmployees) { Console.WriteLine(empl.FirstName); Console.WriteLine(empl.LastName); } Console.WriteLine("----------------------------"); Console.WriteLine("Getting Employees with Id 1"); Employee singleEmployee = employeeRepo.GetEmployeeById(1); Console.WriteLine($"{singleEmployee.Id} {singleEmployee.FirstName} {singleEmployee.LastName}"); //public List<Employee> GetAllEmployeesWithDepartment() < ---Employee objects should have a Department property //public void AddEmployee(Employee employee) //public void UpdateEmployee(int id, Employee employee) < ---Use the SQL UPDATE statement //public void DeleteEmployee(int id) //COPY AND PASTE ABOVE THIS LINE }
static void Main(string[] args) { 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 = 3; var departmentWithId3 = departmentRepo.GetDepartmentById(hardCodedId); Console.WriteLine("-----------"); Console.WriteLine($"Department with id {hardCodedId} is {departmentWithId3.DepartmentName}"); /// heres a break------------------------------------------------------------------------------- /// --------------------------------------------------------------------------------------------- var employeeRepo = new EmployeeRepository(); var allEmployees = employeeRepo.GetAllEmployees(); Console.WriteLine("All Employees"); Console.WriteLine("---------------"); foreach (var employee in allEmployees) { Console.WriteLine(employee.FirstName); } var hardCodedEmployeeId = 2; var employeeWithId3 = employeeRepo.GetEmployeeById(hardCodedEmployeeId); Console.WriteLine("-----------"); Console.WriteLine($"Employee with id {hardCodedEmployeeId} is {employeeWithId3.FirstName}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); var legal = new Department(); Console.WriteLine("What department would you like to add?"); legal.DepartmentName = Console.ReadLine(); departmentRepo.AddDepartment(legal); Console.WriteLine("What Department (ID) would you like to update?"); var departmentToUpdate = Int32.Parse(Console.ReadLine()); Console.WriteLine("What is name of the new department?"); var newDepartmentName = Console.ReadLine(); departmentRepo.UpdateDepartment(departmentToUpdate, new Department { DepartmentName = newDepartmentName }); //Add a new employee departmentRepo.DeleteDepartment(7); departmentRepo.DeleteDepartment(8); departmentRepo.DeleteDepartment(9); }
static void Main(string[] args) { while (true) { /// users chooses from one of these prompts Console.WriteLine("Choose from one of the options below?"); Console.WriteLine("--------------------------------------"); Console.WriteLine("1. Show all deparments"); Console.WriteLine("2. Show specific department by Id"); Console.WriteLine("3. Add new department"); Console.WriteLine("4. Update department Id"); Console.WriteLine("5. Delete department by Id"); Console.WriteLine("6. Show all employees"); Console.WriteLine("7. Show specific employee by Id"); Console.WriteLine("8. Add a new employee"); Console.WriteLine("9. Update an employee"); Console.WriteLine("10. Delete an employee"); var choice = Console.ReadLine(); DepartmentRepository departments = new DepartmentRepository(); EmployeeRepository employees = new EmployeeRepository(); switch (Int32.Parse(choice)) { case 1: Console.WriteLine("Getting all Departments:"); Console.WriteLine(); List <Department> allDepartments = departments.GetAllDepartments(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id} {dept.DeptName}"); } break; case 2: Console.WriteLine("Enter department Id."); var deptChoice = int.Parse(Console.ReadLine()); Console.WriteLine($"Getting department {deptChoice}"); Department singleDepartment = departments.GetDepartmentById(deptChoice); Console.WriteLine($"{singleDepartment.Id}. {singleDepartment.DeptName}"); break; case 3: Console.WriteLine("Enter the name of new department."); var deptName = Console.ReadLine(); Department newDepartment = new Department { DeptName = deptName }; departments.AddDepartment(newDepartment); Console.WriteLine($"Add new {deptName} to Departments."); break; case 4: //Console.WriteLine("Enter the name of the department you wish to update."); //var deptName = Console.ReadLine(); break; case 5: Console.WriteLine("Enter the Id of the deptarment you would like to delete."); var deleteChoice = int.Parse(Console.ReadLine()); departments.DeleteDepartment(deleteChoice); Console.WriteLine($"Department with Id of {deleteChoice} was deleted."); break; case 6: Console.WriteLine("Getting all employees"); Console.WriteLine(""); List <Employee> allEmployees = employees.GetAllEmployees(); foreach (Employee e in allEmployees) { Console.WriteLine($"{e.Id}. {e.FirstName} {e.LastName}"); } break; case 7: Console.WriteLine("Enter employee by Id."); var employeeId = int.Parse(Console.ReadLine()); Console.WriteLine($"Getting employee {employeeId}"); Employee singleEmployee = employees.GetEmployeeById(employeeId); Console.WriteLine($"{singleEmployee.Id} {singleEmployee.FirstName} {singleEmployee.LastName}"); break; case 8: Console.WriteLine("Enter the first name of new employee."); var eFirstName = Console.ReadLine(); Console.WriteLine("Enter the last name of new employee."); var eLastName = Console.ReadLine(); Console.WriteLine("Enter departmentId of new employee."); var eDeptName = int.Parse(Console.ReadLine()); Employee newEmployee = new Employee { FirstName = eFirstName, LastName = eLastName, DepartmentId = eDeptName }; employees.AddEmployee(newEmployee); Console.WriteLine($"Add new {eFirstName} {eLastName} to employees."); break; case 9: //Console.WriteLine("Enter the name of the department you wish to update."); //var deptName = Console.ReadLine(); break; case 10: Console.WriteLine("Enter the Id of the employee you would like to delete."); var deleteEmployee = int.Parse(Console.ReadLine()); employees.DeleteEmployee(deleteEmployee); Console.WriteLine($"Department with Id of {deleteEmployee} was deleted."); break; default: break; } } }
static void Main(string[] args) { var departmentRepo = new DepartmentRepository(); Console.WriteLine("Getting All Departments:"); Console.WriteLine(); List <Department> allDepartments = departmentRepo.GetAllDepartments(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id} {dept.DepartmentName}"); } var hardCodedId = 3; var departmentWithId3 = departmentRepo.GetDepartmentById(hardCodedId); Console.WriteLine("............................."); Console.WriteLine($"Department with Id {hardCodedId} is {departmentWithId3.DepartmentName}"); var employeeRepo = new EmployeeRepository(); List <Employee> allEmployees = employeeRepo.GetAllemployees(); foreach (Employee person in allEmployees) { Console.WriteLine($"{person.Id} {person.FirstName} {person.LastName} working in {person.DeptName}"); } var employee1 = employeeRepo.GetEmployeeById(1); Console.WriteLine("............................."); Console.WriteLine($"Employee with Id 1 is {employee1.FirstName} {employee1.LastName} works in {employee1.DeptName}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); //ADDING UPDATING DEPTS //var newDept = new Department(); //Console.WriteLine("What dept would you like to add?"); //newDept.DepartmentName = Console.ReadLine(); //departmentRepo.AddDepartment(newDept); //Console.WriteLine("what Dept Id to change?"); //var deptToUpdate = Int32.Parse(Console.ReadLine()); //Console.WriteLine("what to call it?"); //var newDeptName = Console.ReadLine(); //departmentRepo.UpdateDepartment(deptToUpdate, new Department { DepartmentName = newDeptName }); //delete department //departmentRepo.DeleteDepartment(1); //ADDING NEW EMPLOYEE //employeeRepo.AddEmployee(new Employee { FirstName = "jojo", LastName = "bob", DepartmentId = 1 }); //UPDATING EMPLOYEE // employeeRepo.UpdateEmployee(4, new Employee { FirstName = "hoho", LastName = "bob", DepartmentId = 1 }); //DELETE EMPLOYEE employeeRepo.DeleteEmployee(4); }
static void Main(string[] args) { while (true) { Console.WriteLine("What would you like to do?"); Console.WriteLine(""); Console.WriteLine("1. Show all departments"); Console.WriteLine("2. Show specific department by Id"); Console.WriteLine("3. Add new department"); Console.WriteLine("4. Update department information"); Console.WriteLine("5. Delete department by Id"); Console.WriteLine("6. Show all employees"); Console.WriteLine("7. Show specific employee by Id"); Console.WriteLine("8. Show all employees by department"); Console.WriteLine("9. Add new employee"); Console.WriteLine("10. Update employee information"); Console.WriteLine("11. Delete employee by Id"); var choice = Console.ReadLine(); DepartmentRepository departmentRepo = new DepartmentRepository(); EmployeeRepository employeeRepo = new EmployeeRepository(); switch (Int32.Parse(choice)) { case 1: Console.WriteLine("Getting All Departments:"); Console.WriteLine(); List <Department> allDepartments = departmentRepo.GetAllDepartments(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id} {dept.DeptName}"); } break; case 2: Console.WriteLine("Enter Id of department"); var departmentChoice = int.Parse(Console.ReadLine()); Console.WriteLine($"Getting department with Id of {departmentChoice}"); Department singleDepartment = departmentRepo.GetDepartmentById(departmentChoice); Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}"); break; case 3: Console.WriteLine("Enter the name of the new department"); var departmentName = Console.ReadLine(); Department newDepartment = new Department { DeptName = departmentName }; departmentRepo.AddDepartment(newDepartment); Console.WriteLine($"Added the new {departmentName} Department!"); break; case 4: Console.WriteLine("Update Department Info"); //TBD break; case 5: Console.WriteLine("Enter the Id of the department you would like to delete"); var deleteDeptChoice = int.Parse(Console.ReadLine()); departmentRepo.DeleteDepartment(deleteDeptChoice); Console.WriteLine($"Department with the Id of {deleteDeptChoice} has been deleted."); break; case 6: Console.WriteLine("Getting All Employees:"); Console.WriteLine(); List <Employee> allEmployees = employeeRepo.GetAllEmployees(); foreach (Employee emp in allEmployees) { Console.WriteLine($"{emp.FirstName} {emp.LastName}"); } break; case 7: Console.WriteLine("Enter the Id of the employee you would like to view"); var chosenEmployeeId = int.Parse(Console.ReadLine()); Employee singleEmployee = employeeRepo.GetEmployeeById(chosenEmployeeId); Console.WriteLine($"Getting Employee with Id of {chosenEmployeeId}."); Console.WriteLine($"{singleEmployee.Id} {singleEmployee.FirstName} {singleEmployee.LastName}"); break; case 8: List <Employee> allDepartmentEmployees = employeeRepo.GetAllEmployeesWithDepartment(); foreach (Employee emp in allDepartmentEmployees) { Console.WriteLine($"{emp.FirstName} {emp.LastName} - {emp.Department.DeptName}"); } break; case 9: Console.WriteLine("Enter new employee's first name"); var newEmployeeFirstName = Console.ReadLine(); Console.WriteLine("Enter new employee's last name"); var newEmployeeLastName = Console.ReadLine(); Console.WriteLine("Enter new employee's department Id"); var newEmployeeDeptId = int.Parse(Console.ReadLine()); Employee newEmployee = new Employee { FirstName = newEmployeeFirstName, LastName = newEmployeeLastName, DepartmentId = newEmployeeDeptId }; employeeRepo.AddEmployee(newEmployee); Console.WriteLine($"Added {newEmployee.FirstName} {newEmployee.LastName} as a new employee!"); break; case 10: Console.WriteLine("Update Employee Info"); //TBD break; case 11: Console.WriteLine("Enter the Id of the employee you would like to delete"); var deleteEmployeeId = int.Parse(Console.ReadLine()); employeeRepo.DeleteEmployee(deleteEmployeeId); Console.WriteLine($"Employee with the Id of {deleteEmployeeId} has been deleted"); break; default: break; } } }
static void Main(string[] args) { //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.GetAllEmployees(); Console.WriteLine("Press 1 for Departments: "); Console.WriteLine("Press 2 for Employees: "); Console.WriteLine("Press 3 for Company Report: "); Console.WriteLine("Press 4 to exit: "); string option = Console.ReadLine(); if (option == "1") { Console.Clear(); Console.WriteLine("---DEPARTMENTS---"); Console.WriteLine("Press 1 to add a Department"); Console.WriteLine("Press 2 Delete a Department"); Console.WriteLine("Press 3 to return to main"); 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()); deptRepo.DeleteDepartment(deleteDeptInput); 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 release an Employee"); Console.WriteLine("Press 3 to return to main"); 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("Employee to be released"); for (int 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: 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("End"); break; } } }
static void Main(string[] args) { //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.GetAllEmployees(); 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.First(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; } } }
static void Main(string[] args) { // Get All Departments var departmentRepo = new DepartmentRepository(); var allDepartments = departmentRepo.GetAllDepartments(); Console.WriteLine("All Departments"); Console.WriteLine("---------------"); foreach (var dept in allDepartments) { Console.WriteLine(dept.DepartmentName); } // Get Department by Id var hardCodedId = 3; var departmentWithId3 = departmentRepo.GetDepartmentById(hardCodedId); Console.WriteLine("---------------"); Console.WriteLine($"Department with id {hardCodedId} is {departmentWithId3.DepartmentName}"); // Get all Employees var employeeRepo = new EmployeeRepository(); var allEmployees = employeeRepo.GetAllEmployees(); Console.WriteLine("All Employees"); Console.WriteLine("-------------"); foreach (var employee in allEmployees) { Console.WriteLine(employee.FirstName); Console.WriteLine(employee.LastName); } // Get Employee by Id var emHardCodedId = 4; var employeeWithId4 = employeeRepo.GetEmployeeById(emHardCodedId); Console.WriteLine("-------------"); Console.WriteLine($"{employeeWithId4.FirstName}{employeeWithId4.LastName}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); // Adding new department var legal = new Department(); Console.WriteLine("What department would you lke to add?"); legal.DepartmentName = Console.ReadLine(); departmentRepo.AddDepartment(legal); // Updating a department Console.WriteLine("What department 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 }); // Deleting a department departmentRepo.DeleteDepartment(7); departmentRepo.DeleteDepartment(8); departmentRepo.DeleteDepartment(9); }
static void Main(string[] args) { var departmentRepo = new DepartmentRepository(); var allDepartments = departmentRepo.GetAllDepartments(); Console.WriteLine("All Departments"); Console.WriteLine("----------------"); foreach (var dept in allDepartments) { Console.WriteLine(dept.DepartmentName); } var hardCodeId = 3; var departmentWithId3 = departmentRepo.GetDepartmentById(hardCodeId); Console.WriteLine("-----------------"); Console.WriteLine($"Department with id {hardCodeId} is {departmentWithId3.DepartmentName}"); var employeeRepo = new EmployeeRepository(); var allEmployees = employeeRepo.GetAllEmployees(); Console.WriteLine("All Employees"); Console.WriteLine("----------------"); foreach (var emp in allEmployees) { Console.WriteLine(emp.FirstName); Console.WriteLine(emp.LastName); } var empHardCodeId = 3; var empWithId3 = employeeRepo.GetEmployeeById(empHardCodeId); Console.WriteLine("-----------------"); Console.WriteLine($"Department with id {empHardCodeId} is {empWithId3.FirstName} {empWithId3.LastName}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); var allEmployeesWithDept = employeeRepo.GetAllEmployeesWithDepartment(); Console.WriteLine("Employees with Department"); Console.WriteLine("------------------"); foreach (var emp in allEmployeesWithDept) { Console.WriteLine(emp.FirstName); Console.WriteLine(emp.LastName); Console.WriteLine(emp.Department); } var legal = new Department(); Console.WriteLine("What department would you like to add?"); legal.DepartmentName = Console.ReadLine(); departmentRepo.AddDepartment(legal); 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 }); departmentRepo.DeleteDepartment(7); departmentRepo.DeleteDepartment(8); departmentRepo.DeleteDepartment(9); }
static void Main(string[] args) // ******************** GET ALL ******************** { DepartmentRepository departmentRepo = new DepartmentRepository(); Console.WriteLine("Getting All Departments:"); Console.WriteLine(); List <Department> allDepartments = departmentRepo.GetAllDepartments(); foreach (Department dept in allDepartments) { Console.WriteLine($"{dept.Id} {dept.DeptName}"); } EmployeeRepository employeeRepo = new EmployeeRepository(); Console.WriteLine(); Console.WriteLine("Getting All Employees:"); Console.WriteLine(); List <Employee> allEmployees = employeeRepo.GetAllEmployees(); foreach (Employee e in allEmployees) { Console.WriteLine($"{e.Id} {e.FirstName} {e.LastName} {e.DepartmentId}"); } // ******************** GET ONE ******************** Console.WriteLine("----------------------------"); Console.WriteLine("getting DEPARTMENT with id 1"); Department singleDepartment = departmentRepo.GetDepartmentById(1); Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}"); Console.WriteLine("----------------------------"); Console.WriteLine("getting EMPLOYEE with id 1"); Employee singleEmployee = employeeRepo.getEmployeeById(1); Console.WriteLine($"{singleEmployee.Id} {singleEmployee.FirstName} {singleEmployee.LastName} {singleEmployee.DepartmentId}"); // ******************** GET ALL + DEPT ******************** DepartmentRepository departmentRepoAll = new DepartmentRepository(); Console.WriteLine(); Console.WriteLine("---------------------------------------"); Console.WriteLine("Getting All Employees With Departments:"); List <Employee> allEmployeesAll = employeeRepo.GetAllEmployeesWithDepartment(); foreach (Employee e in allEmployeesAll) { Console.WriteLine($"{e.Id} {e.FirstName} {e.LastName} - {e.Department.DeptName}"); } // ******************** ADD ******************** Department legalDept = new Department { DeptName = "Legal" }; departmentRepo.AddDepartment(legalDept); // departmentRepo has been initialized in line 13 Console.WriteLine("-------------------------------"); Console.WriteLine("Added the new Legal Department!"); Employee cherkesky = new Employee { FirstName = "Guy", LastName = "Cherkesky", DepartmentId = 2 }; employeeRepo.AddEmployee(cherkesky); // employeeRepo has been initialized in line 25 Console.WriteLine("-------------------------------"); Console.WriteLine("Added the new talented Employee!"); }
static void Main(string[] args) { var departmentRepo = new DepartmentRepository(); //Console.WriteLine("Getting All Departments:"); //Console.WriteLine(); List <Department> allDepartments = departmentRepo.GetAllDepartments(); //foreach (Department dept in allDepartments) //{ // Console.WriteLine($"{dept.Id} {dept.DeptName}"); //} //Console.WriteLine("----------------------------"); //Console.WriteLine("Getting Department with Id 1"); //Department singleDepartment = departmentRepo.GetDepartmentById(1); //Console.WriteLine($"{singleDepartment.Id} {singleDepartment.DeptName}"); //Department legalDept = new Department //{ // DeptName = "Legal" //}; //departmentRepo.AddDepartment(legalDept); //Console.WriteLine("-------------------------------"); //Console.WriteLine("Added the new Legal Department!"); var employeeRepo = new EmployeeRepository(); var employees = employeeRepo.GetAllEmployees(); //foreach(var employee in employees) //{ // Console.WriteLine($"{employee.FirstName} {employee.LastName} is in {employee.Department.DeptName}"); //} while (true) { Console.WriteLine("Select an option "); Console.WriteLine("1. Add A Department"); Console.WriteLine("2. Add An Employee"); Console.WriteLine("3. Update A Department"); Console.WriteLine("4. Update An Employee"); Console.WriteLine("5. Delete A Department"); Console.WriteLine("6. Delete A Employee"); switch (int.Parse(Console.ReadLine())) { case 1: Console.WriteLine("Enter your department name"); var departmentNameEntered = Console.ReadLine(); Department newDept = new Department { DeptName = departmentNameEntered }; departmentRepo.AddDepartment(newDept); Console.WriteLine("You have added your department!"); break; case 2: Console.WriteLine("Enter the employees first name"); var firstNameEntered = Console.ReadLine(); Console.WriteLine("Enter the employees last name"); var lastNameEntered = Console.ReadLine(); Console.WriteLine("Select the department id"); foreach (var department in allDepartments) { Console.WriteLine($" {department.Id} {department.DeptName}"); } var deptIdEntered = int.Parse(Console.ReadLine()); Employee newEmployee = new Employee { FirstName = firstNameEntered, LastName = lastNameEntered, DepartmentId = deptIdEntered }; employeeRepo.CreateNewEmployee(newEmployee); Console.WriteLine("You have added an employee"); break; case 3: Console.WriteLine("Enter the department id you want to update"); foreach (var department in allDepartments) { Console.WriteLine($" {department.Id} {department.DeptName}"); } var DeptId = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the updated department name"); var updatedDeptName = Console.ReadLine(); var updatedDept = new Department { Id = DeptId, DeptName = updatedDeptName }; departmentRepo.UpdateDepartment(DeptId, updatedDept); break; case 4: Console.WriteLine("Enter the id of the employee you want to update"); foreach (var employee in employees) { Console.WriteLine($" {employee.Id} {employee.FirstName} {employee.LastName}"); } var updatedEmpId = int.Parse(Console.ReadLine()); Console.WriteLine("Enter updated first name:"); var updatedFirst = Console.ReadLine(); Console.WriteLine("Enter updated last name"); var updatedLast = Console.ReadLine(); Console.WriteLine("Enter the updated department"); foreach (var department in allDepartments) { Console.WriteLine($" {department.Id} {department.DeptName}"); } var updatedDeptId = int.Parse(Console.ReadLine()); var updatedEmployee = new Employee { FirstName = updatedFirst, LastName = updatedLast, DepartmentId = updatedDeptId }; employeeRepo.UpdateEmployee(updatedEmpId, updatedEmployee); break; case 5: Console.WriteLine("Select the department you want to delete"); foreach (var department in allDepartments) { Console.Write($"{department.Id} {department.DeptName} "); var relatedEmp = employees.Where(emp => emp.DepartmentId == department.Id).ToList(); foreach (var emp in relatedEmp) { Console.Write($" {emp.Id} {emp.FirstName} {emp.LastName}"); } Console.WriteLine(); } var selectedDept = int.Parse(Console.ReadLine()); foreach (var emp in employees) { try { if (emp.Department.Id != selectedDept) { departmentRepo.DeleteDepartment(selectedDept); break; } } catch { Console.WriteLine("Delete the employees in that department first"); break; } } break; case 6: Console.WriteLine("Select the employee you would like to fire"); foreach (var emp in employees) { Console.WriteLine($"{emp.Id} {emp.FirstName} {emp.LastName} {emp.Department.DeptName}"); } var empId = int.Parse(Console.ReadLine()); employeeRepo.DeleteEmployee(empId); break; default: break; } } }