private void ReadEmployee() { try { List <Employee> employees = Query.GetEmployees().ToList(); UserInterface.DisplayEmployees(employees); int employeeid = UserInterface.GetIntegerData("id number", "the employee's"); Employee employee = Query.GetEmployeeById(employeeid); Query.RunEmployeeQueries(employee, "read"); Console.WriteLine("Press Enter to continue."); Console.ReadLine(); } catch { Console.Clear(); UserInterface.DisplayUserOptions("Employee not found please try again or type exit;"); return; } }
private void UpdateEmployee() { List <Employee> employees = Query.GetEmployees().ToList(); UserInterface.DisplayEmployees(employees); int employeeid = UserInterface.GetIntegerData("id number", "the employee's"); Employee employee = Query.GetEmployeeById(employeeid); try { employee = UpdateEmployeeInfo(employee); Query.RunEmployeeQueries(employee, "update"); UserInterface.DisplayUserOptions("Employee update successful. Press Enter to continue."); Console.ReadLine(); } catch { Console.Clear(); UserInterface.DisplayUserOptions("Employee update unsuccessful please try again or type exit;"); return; } }
private void RemoveEmployee() { List <Employee> employees = Query.GetEmployees().ToList(); UserInterface.DisplayEmployees(employees); int employeeid = UserInterface.GetIntegerData("id number", "the employee's"); Employee employee = Query.GetEmployeeById(employeeid); try { Console.Clear(); Query.RunEmployeeQueries(employee, "delete"); UserInterface.DisplayUserOptions("Employee successfully removed. Press Enter to continue."); Console.ReadLine(); } catch { Console.Clear(); UserInterface.DisplayUserOptions("Employee removal unsuccessful please try again or type exit"); RemoveEmployee(); } }
internal static Employee RunEmployeeQueries(Employee employee, string action) { HumaneSocietyDataContext db = new HumaneSocietyDataContext(); switch (action) { case "create": db.Employees.InsertOnSubmit(employee); db.SubmitChanges(); return(null); //break; case "read": if (employee.EmployeeNumber != null) { employee = db.Employees.Where(e => e.EmployeeNumber == employee.EmployeeNumber).First(); } if (employee.EmployeeId != 0) { employee = db.Employees.Where(e => e.EmployeeId == employee.EmployeeId).First(); } UserInterface.DisplayEmployeeInfo(employee); Console.WriteLine("\nPress enter to continue:"); Console.ReadLine(); return(employee); //break; case "update": Employee thisEmployee = db.Employees.Where(e => e.EmployeeId == employee.EmployeeId).Single(); thisEmployee.LastName = employee.LastName; thisEmployee.FirstName = employee.FirstName; thisEmployee.EmployeeId = employee.EmployeeId; thisEmployee.UserName = employee.UserName; thisEmployee.Password = employee.Password; thisEmployee.Email = employee.Email; db.SubmitChanges(); Console.Clear(); Console.WriteLine("Updated:"); UserInterface.DisplayEmployeeInfo(employee); Console.WriteLine("\nPress enter to continue:"); Console.ReadLine(); return(null); //break; case "display": // display Console.Clear(); UserInterface.DisplayEmployees(db.Employees.OrderBy(e => e.LastName).ThenBy(e => e.FirstName)); // DisplayEmployees return(null); //break; case "delete": employee = db.Employees.Where(e => e.LastName == employee.LastName && e.EmployeeNumber == employee.EmployeeNumber).First(); db.Employees.DeleteOnSubmit(employee); db.SubmitChanges(); return(null); //break; default: return(null); } }