Пример #1
0
        /// <summary>
        /// Changes user in dictionary
        /// </summary>
        /// <param name="dictionary">Dictionary to pass in</param>
        /// <param name="empID">Employee ID to change</param>
        /// <returns></returns>
        public Dictionary <int, Employee> ChangeUserInDictionary(Dictionary <int, Employee> dictionary, int empID)
        {
            PayrollConsoleReader payrollConsoleReader = new PayrollConsoleReader();

            try
            {
                if (dictionary.ContainsKey(empID))
                {
                    dictionary.Remove(empID, out Employee emp);
                    emp.FirstName   = payrollConsoleReader.GetFirstNameConsole();
                    emp.LastName    = payrollConsoleReader.GetLastNameConsole();
                    emp.HoursWorked = payrollConsoleReader.GetHoursWorkedConsole();
                    emp.Payrate     = payrollConsoleReader.GetPayrateConsole();
                    Console.WriteLine("Key: " + empID);
                    Console.WriteLine("Value: " + emp.FirstName + " " + emp.LastName);
                    dictionary.Add(empID, emp);
                }
                else
                {
                    Console.WriteLine("error!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error {e}");
            }

            return(dictionary);
        }
Пример #2
0
        /// <summary>
        /// Prints the menu for employee options
        /// </summary>
        /// <returns>A dictionary</returns>
        public Dictionary <int, Employee> PrintMenu()
        {
            char                       option;
            var                        empID                = 0;
            List <Employee>            empList              = new List <Employee>();
            PayrollManager             payrollManager       = new PayrollManager();
            PayrollConsoleReader       payrollConsoleReader = new PayrollConsoleReader();
            Dictionary <int, Employee> dictionary           = new Dictionary <int, Employee>();

            Console.WriteLine("c. Create a new employee");
            Console.WriteLine("h. Change an employee");
            Console.WriteLine("u. Update an employee");
            Console.WriteLine("d. Delete records");
            Console.WriteLine("q. quit the program");
            option = Console.ReadKey().KeyChar;

            while (option != 'q')
            {
                switch (option)
                {
                case 'q':
                    System.Environment.Exit(0);
                    break;

                case 'c':
                    Console.WriteLine("");
                    empID = payrollConsoleReader.GetEmployeeIDConsole();
                    Employee emp = payrollConsoleReader.CreateAnEmployee(empID);
                    dictionary.Add(empID, emp);
                    break;

                case 'h':
                    empID      = payrollConsoleReader.GetEmployeeIDConsole();
                    dictionary = payrollManager.ChangeUserInDictionary(dictionary, empID);
                    break;

                case 'u':
                    empID      = payrollConsoleReader.GetEmployeeIDConsole();
                    dictionary = payrollManager.UpdateUserInDictionary(dictionary, empID);
                    break;

                case 'd':
                    empID      = payrollConsoleReader.GetEmployeeIDConsole();
                    dictionary = payrollManager.RemoveUserInDictionary(dictionary, empID);
                    break;

                default:
                    Console.WriteLine(" ");
                    Console.WriteLine("please press 'q', 'c', 'h', 'u', 'd'");
                    break;
                }

                option = Console.ReadKey().KeyChar;
                Console.WriteLine("");
            }

            return(dictionary);
        }
Пример #3
0
        /// <summary>
        /// Creates an employee
        /// </summary>
        /// <param name="empID">The employee ID desired</param>
        /// <returns>An employee object</returns>
        public Employee CreateAnEmployee(int empID)
        {
            string  firstName;
            string  lastName;
            int     hoursWorked;
            decimal payrate;


            PayrollConsoleReader payrollConsoleReader = new PayrollConsoleReader();

            firstName   = payrollConsoleReader.GetFirstNameConsole();
            lastName    = payrollConsoleReader.GetLastNameConsole();
            hoursWorked = payrollConsoleReader.GetHoursWorkedConsole();
            payrate     = payrollConsoleReader.GetPayrateConsole();

            return(new Employee(firstName, lastName, empID, hoursWorked, payrate));
        }