public void RunDeleteView() { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Please enter the Id of the employee you wish to delete."); int id = Convert.ToInt32(Console.ReadLine()); int index = _employees.Find(id); if (index != -1) { Employee employee = _employees[index]; Console.WriteLine($"Are you sure you wish to delete employee with Id({employee.Id})? (y/n)"); ConsoleKey consoleKey = Console.ReadKey().Key; if (consoleKey == ConsoleKey.Y) { _employees.Delete(index); } } else { Console.Clear(); Console.WriteLine(EmployeeCommonOutputText.GetApplicationHeading()); Console.WriteLine(EmployeeCommonOutputText.GetEmployeeNotFoundMessage(id)); Console.ReadKey(); } }
static void Main(string[] args) { bool endApplication = false; Employees employees = new Employees(); EmployeeRecordsView employeeRecordsView = EmployeeObjectFactory.EmployeeRecordsViewObject(employees); while (!endApplication) { Console.Clear(); Console.WriteLine(EmployeeCommonOutputText.GetApplicationHeading()); employeeRecordsView.RunRecordsView(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(EmployeeCommonOutputText.GetInstructions()); ConsoleKey instructionKey = Console.ReadKey().Key; switch (instructionKey) { case ConsoleKey.C: EmployeeCreateView employeeCreateView = EmployeeObjectFactory.EmployeeCreateViewObject(employees); employeeCreateView.RunCreateView(); break; case ConsoleKey.R: EmployeeReadView employeeReadView = EmployeeObjectFactory.EmployeeReadViewObject(employees); employeeReadView.RunReadView(); break; case ConsoleKey.U: Console.Clear(); Console.WriteLine("Update functionality not yet implemented."); Console.ReadKey(); break; case ConsoleKey.D: Console.Clear(); Console.WriteLine("Delete functionality not yet implemented."); Console.ReadKey(); break; default: endApplication = true; break; } } Console.ReadKey(); }
public void RunUpdateView() { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Please enter the Id of the employee you wish to edit."); int id = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Console.WriteLine(EmployeeCommonOutputText.GetApplicationHeading()); int index = _employees.Find(id); if (index != -1) { string firstName = null; string lastName = null; string annualSalary = null; string gender = null; string isManager = null; Employee employee = _employees[index]; Console.WriteLine(EmployeeCommonOutputText.GetUpdateHeading(employee)); Console.WriteLine(EmployeeCommonOutputText.GetUpdateViewAdditionalInstructions()); Console.Write($"First Name ({employee.FirstName}): "); firstName = Console.ReadLine(); Console.Write($"Last Name ({employee.LastName}): "); lastName = Console.ReadLine(); Console.Write($"Annual Salary ({employee.AnnualSalary}): "); annualSalary = Console.ReadLine(); Console.Write($"Gender ({employee.Gender}): "); gender = Console.ReadLine(); Console.Write($"Manager ({employee.IsManger}): "); isManager = Console.ReadLine(); _employees.Update(employee, (String.IsNullOrWhiteSpace(firstName) ? employee.FirstName : firstName), (String.IsNullOrWhiteSpace(lastName) ? employee.LastName : lastName), (String.IsNullOrWhiteSpace(annualSalary) ? employee.AnnualSalary : Decimal.Parse(annualSalary, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture)), (String.IsNullOrWhiteSpace(gender) ? employee.Gender : Convert.ToChar(gender)), (String.IsNullOrWhiteSpace(isManager) ? employee.IsManger : Convert.ToBoolean(isManager)) ); } else { Console.WriteLine(EmployeeCommonOutputText.GetEmployeeNotFoundMessage(id)); Console.ReadKey(); } }
public void RunRecordsView() { Console.WriteLine(EmployeeCommonOutputText.GetColumnHeadings()); Console.WriteLine(); foreach (Employee emp in _employees) { Console.Write(emp.GetEmployeeInformation()); } }
static void Main(string[] args) { Employees employees = new Employees(); EmployeeRecordsView employeeRecordsView = new EmployeeRecordsView(employees); Console.WriteLine(EmployeeCommonOutputText.GetApplicationHeading()); employeeRecordsView.RunRecordsView(); Console.ReadKey(); }
public void RunCreateView() { string firstName = null; string lastName = null; decimal annualSalary = 0; char gender = '\0'; bool isManager = false; Console.Clear(); Console.WriteLine(EmployeeCommonOutputText.GetApplicationHeading()); Console.WriteLine(); Console.WriteLine(EmployeeCommonOutputText.GetCreateHeading()); Console.Write("First Name: "); firstName = Console.ReadLine(); Console.Write("Last Name: "); lastName = Console.ReadLine(); Console.Write("Annual Salary: "); annualSalary = decimal.Parse(Console.ReadLine(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); Console.Write("Gender (m/f): "); gender = Convert.ToChar(Console.ReadLine()); Console.Write("Manager (true/false): "); isManager = Convert.ToBoolean(Console.ReadLine()); Console.WriteLine(); Console.WriteLine("Please press the [S] key to save the new employee record to the system or any other key to cancel."); ConsoleKey consoleKey = Console.ReadKey().Key; if (consoleKey == ConsoleKey.S) { _employees.Add(EmployeeObjectFactory.CreateNewEmployeeObject(firstName, lastName, annualSalary, gender, isManager)); } }
public void RunReadView() { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Please enter the id of the employee you wish to view."); int id = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Console.WriteLine(EmployeeCommonOutputText.GetApplicationHeading()); int index = _employees.Find(id); if (index != -1) { Employee employee = _employees[index]; Console.WriteLine(EmployeeCommonOutputText.GetEmployeeRecordHeading(employee)); Console.WriteLine($"Id: {employee.Id}"); Console.WriteLine($"First Name: {employee.FirstName}"); Console.WriteLine($"Last Name: {employee.LastName}"); Console.WriteLine($"Annual Salary: {employee.AnnualSalary}"); Console.WriteLine($"Gender: {employee.Gender}"); Console.WriteLine($"Manager: {employee.IsManger}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Please press any key to return to the main view..."); } else { Console.WriteLine(EmployeeCommonOutputText.GetEmployeeNotFoundMessage(id)); } Console.ReadKey(); }