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();
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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();
        }