private static void UpdateEmployee() { try { int updateEmployeeID; Console.WriteLine("Enter EmployeeID to Update Details:"); updateEmployeeID = int.Parse(Console.ReadLine()); Employee updatedEmployee = EmsBL.SearchEmployeeBL(updateEmployeeID); if (updatedEmployee != null) { Console.WriteLine("Update Employee Name :"); updatedEmployee.EmployeeName = Console.ReadLine(); Console.WriteLine("Update PhoneNumber :"); updatedEmployee.EmployeeContactNo = long.Parse(Console.ReadLine()); bool EmployeeUpdated = EmsBL.UpdateEmployeeBL(updatedEmployee); if (EmployeeUpdated) { Console.WriteLine("Employee Details Updated"); } else { Console.WriteLine("Employee Details not Updated "); } } else { Console.WriteLine("No Employee Details Available"); } } catch (EmsException ex) { Console.WriteLine(ex.Message); } }
private static void AddEmployee() { try { Employee newEmployee = new Employee(); Console.WriteLine("Enter Employee ID :"); newEmployee.EmployeeID = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Employee Name :"); newEmployee.EmployeeName = Console.ReadLine(); Console.WriteLine("Enter Employee Department:"); newEmployee.EmployeeDepartment = Console.ReadLine(); Console.WriteLine("Enter Contact No.:"); newEmployee.EmployeeContactNo = long.Parse(Console.ReadLine()); Console.WriteLine("Enter Email ID:"); newEmployee.EmployeeEmail = Console.ReadLine(); Console.WriteLine("Enter Employee Address:"); newEmployee.EmployeeAddress = Console.ReadLine(); bool guestAdded = EmsBL.AddEmployeeBL(newEmployee); if (guestAdded) { Console.WriteLine("Employee Added"); } else { Console.WriteLine("Employee not Added"); } } catch (EmsException ex) { Console.WriteLine(ex.Message); } }
private static void DeleteEmployee() { try { int deleteEmployeeID; Console.WriteLine("Enter Employee ID to Delete:"); deleteEmployeeID = int.Parse(Console.ReadLine()); Employee deleteEmployee = EmsBL.SearchEmployeeBL(deleteEmployeeID); if (deleteEmployee != null) { bool employeedeleted = EmsBL.DeleteEmployeeBL(deleteEmployeeID); if (employeedeleted) { Console.WriteLine("Employee Deleted"); } else { Console.WriteLine("Employee not Deleted "); } } else { Console.WriteLine("No Employee Details Available"); } } catch (EmsException ex) { Console.WriteLine(ex.Message); } }
private static void SearchEmployeeByID() { try { int searchEmployeeID; Console.WriteLine("Enter EmployeeID to Search:"); searchEmployeeID = int.Parse(Console.ReadLine()); Employee searchEmployee = EmsBL.SearchEmployeeBL(searchEmployeeID); if (searchEmployee != null) { Console.WriteLine("******************************************************************************"); Console.WriteLine("EmployeeID\t\tName\t\tPhoneNumber"); Console.WriteLine("******************************************************************************"); Console.WriteLine("{0}\t\t{1}\t\t{2}", searchEmployee.EmployeeID, searchEmployee.EmployeeName, searchEmployee.EmployeeContactNo); Console.WriteLine("******************************************************************************"); } else { Console.WriteLine("No Employee Details Available"); } } catch (EmsException ex) { Console.WriteLine(ex.Message); } }
private static void ListAllEmployees() { try { List <Employee> employeeList = EmsBL.GetAllEmployeeBL(); if (employeeList != null) { Console.WriteLine("******************************************************************************"); Console.WriteLine("EmployeeID\t\tName\t\tDepartment\t\tContactNumber\t\tEmailAddress\t\tAddress"); Console.WriteLine("******************************************************************************"); foreach (Employee employee in employeeList) { Console.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}\t\t{5}", employee.EmployeeID, employee.EmployeeName, employee.EmployeeDepartment, employee.EmployeeContactNo, employee.EmployeeEmail, employee.EmployeeAddress); } Console.WriteLine("******************************************************************************"); } else { Console.WriteLine("No Employee Details Available"); } } catch (EmsException ex) { Console.WriteLine(ex.Message); } }
private static void DeleteEmployee() { int employeeId; do { Console.WriteLine("Enter empId to delete:"); } while (!int.TryParse(Console.ReadLine(), out employeeId)); Employee employee = EmsBL.GetEmployeeById(employeeId); if (employee == null) { Console.WriteLine("Employee does not exists:"); } else { bool isDeleted = EmsBL.DeleteEmployee(employee); if (isDeleted) { Console.WriteLine("Employee deleted"); } else { Console.WriteLine("Delete failed"); } } }
private static void DeleteDepartment() { int departmentId; do { Console.WriteLine("Enter the department ID"); } while (!int.TryParse(Console.ReadLine(), out departmentId)); Department department = EmsBL.GetDepartmentById(departmentId); if (department == null) { Console.WriteLine("Department does not exist"); } else { bool isDeleted = EmsBL.DeleteDepartment(department); if (isDeleted) { Console.WriteLine("Department deleted"); } else { Console.WriteLine("Delete failed"); } } }
private static void ListEmployees() { IEnumerable <Employee> employees = EmsBL.GetEmployeeList(); foreach (var emp in employees) { Console.WriteLine(emp); } }
private static void ListDepartment() { IEnumerable <Department> departments = EmsBL.GetDepartmentList(); foreach (var department in departments) { Console.WriteLine(department); } }
private static void UpdateDepartment() { int departmentId; do { Console.WriteLine("Enter the department ID"); } while (!int.TryParse(Console.ReadLine(), out departmentId)); Department department = EmsBL.GetDepartmentById(departmentId); if (department == null) { Console.WriteLine("Department does not exist"); } else { string departmentName; do { Console.WriteLine("Enter Department Name: "); departmentName = Console.ReadLine(); } while (string.IsNullOrEmpty(departmentName)); department.Name = departmentName; bool isUpdated = EmsBL.UpdateDepartment(department); if (isUpdated) { Console.WriteLine("Department updated Successfully"); } else { Console.WriteLine("Update Department Failed"); } } }
private static void AddDepartment() { Department department = new Department(); string name; do { Console.WriteLine("Enter department Name"); name = Console.ReadLine(); } while (string.IsNullOrEmpty(name)); department.Name = name; bool isAdded = EmsBL.AddDepartment(department); if (isAdded) { Console.WriteLine("Department added successfully"); } else { Console.WriteLine("Department add failed"); } }
private static void ShowEmployeeDetails() { int employeeId; do { Console.WriteLine("Enter employee id for getting details:"); } while (!int.TryParse(Console.ReadLine(), out employeeId)); Employee employee = EmsBL.GetEmployeeById(employeeId); if (employee == null) { Console.WriteLine("Employee does not exists"); } else { bool isFound = EmsBL.EmployeeDetails(employee); if (isFound) { Console.WriteLine("Employee found successfully"); Console.WriteLine(employee); } } }
private static void AddEmployee() { Employee emp = new Employee(); string name; do { Console.WriteLine("Enter employee name: "); name = Console.ReadLine(); } while (string.IsNullOrEmpty(name)); emp.Name = name; DateTime dateOfJoining; string input; do { Console.WriteLine("Enter Date of Joining (YYYY/MM/DD):"); input = Console.ReadLine(); } while (!DateTime.TryParse(input, out dateOfJoining)); emp.DateOfJoining = dateOfJoining; double salary; do { Console.WriteLine("Enter employee salary"); input = Console.ReadLine(); } while (!Double.TryParse(input, out salary)); emp.Salary = salary; string email; do { Console.WriteLine("Enter email:"); email = Console.ReadLine(); } while (string.IsNullOrEmpty(email)); emp.Mail = email; Gender gender; do { foreach (Gender item in Enum.GetValues(typeof(Gender))) { Console.WriteLine("{0}. {1}", (int)item, item); } input = Console.ReadLine(); } while (Enum.IsDefined(typeof(Gender), input)); emp.Gender = (Gender)Convert.ToInt32(input); string hobbies; do { Console.WriteLine("Enter Hobbies:"); hobbies = Console.ReadLine(); } while (string.IsNullOrEmpty(hobbies)); emp.Hobbies = hobbies; int departmentId; do { Console.WriteLine("Enter department id"); input = Console.ReadLine(); } while (!int.TryParse(input, out departmentId)); emp.DepartmentId = departmentId; bool isAdded = EmsBL.AddEmployee(emp); if (isAdded) { Console.WriteLine("Employee added successfully"); } else { Console.WriteLine("Employee add failed"); } }
private static void UpdateEmployee() { int employeeId; do { Console.WriteLine("Enter empId to update:"); } while (!int.TryParse(Console.ReadLine(), out employeeId)); Employee employee = EmsBL.GetEmployeeById(employeeId); if (employee == null) { Console.WriteLine("Employee does not exists:"); } else { string name; do { Console.WriteLine("Enter employee name: "); name = Console.ReadLine(); } while (string.IsNullOrEmpty(name)); employee.Name = name; DateTime dateOfJoining; string input; do { Console.WriteLine("Enter Date of Joining (YYYY/MM/DD):"); input = Console.ReadLine(); } while (!DateTime.TryParse(input, out dateOfJoining)); employee.DateOfJoining = dateOfJoining; double salary; do { Console.WriteLine("Enter employee salary"); input = Console.ReadLine(); } while (!Double.TryParse(input, out salary)); employee.Salary = salary; string email; do { Console.WriteLine("Enter email:"); email = Console.ReadLine(); } while (string.IsNullOrEmpty(email)); employee.Mail = email; //Gender gender; do { foreach (Gender item in Enum.GetValues(typeof(Gender))) { Console.WriteLine("{0}. {1}", (int)item, item); } input = Console.ReadLine(); } while (Enum.IsDefined(typeof(Gender), input)); employee.Gender = (Gender)Convert.ToInt32(input); string hobbies; do { Console.WriteLine("Enter Hobbies:"); hobbies = Console.ReadLine(); } while (string.IsNullOrEmpty(hobbies)); employee.Hobbies = hobbies; int departmentId; do { Console.WriteLine("Enter department id"); input = Console.ReadLine(); } while (!int.TryParse(input, out departmentId)); employee.DepartmentId = departmentId; bool isUpdated = EmsBL.UpdateEmployee(employee); if (isUpdated) { Console.WriteLine("Employee updated"); } else { Console.WriteLine("Update failed"); } } }