Esempio n. 1
0
        static void AddEmployee(ref List <Employee> employeeList)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Adding an employee");
            Console.ForegroundColor = ConsoleColor.Cyan;
            string     fname;
            string     lname;
            string     qualification;
            Department department = Department.IT;

            Console.WriteLine("Enter employee first name");
            fname = Console.ReadLine().Trim();
            Console.WriteLine("Enter employee last name");
            lname = Console.ReadLine().Trim();
            int flag = 1;

qualifiactionBlock:
            try                                                                                                                    //Exception handling
            {
                flag = 1;
                Console.WriteLine("Enter employee qualification");
                qualification = Console.ReadLine().Trim();
                if (qualification == "")
                {
                    throw new ArgumentNullException("Qualification cannot be empty");                                              //Throwing a Custom Exception
                }
                if (qualification == "BE" || qualification == "BCA" || qualification == "BSC")
                {
                    department = Department.IT;
                }
                else if (qualification == "BCom" || qualification == "MCom" || qualification == "CA")
                {
                    department = Department.Accounts;
                }
                else
                {
                    throw new InvalidOperationException("Please enter a valid value for qualification");                            //Throwing a Custom Exception
                }
                flag = 0;
            }
            catch (ArgumentNullException exc)
            {
                Console.WriteLine(exc.Message);
                WriteErrorsToFile(exc);
            }
            if (flag == 1)
            {
                goto qualifiactionBlock;
            }
            Employee          employee = new Employee(fname, lname);
            DepartmentUpdated update   = employee.UpdateDepartment;

            update(department);
            employeeList.Add(employee);
        }
Esempio n. 2
0
 public void Apply(DepartmentUpdated @event)
 {
     Name      = @event.Name;
     Budget    = @event.Budget;
     StartDate = @event.Startdate;
 }