Ejemplo n.º 1
0
 public bool AddNewEmployeeToDb(string title, string firstName, string middleName, string lastName,
                                string phoneNumber, string email, Address personalAddress,
                                int employeeNumber, DateTime dateOfBirth, string ppsn, double wage, int employeeCategory,
                                int employeeCardNumber, DateTime hireDate, string photo)
 {
     try
     {
         int maxId = 0;
         // need some code to avoid dulicate usernames
         // maybe add some logic (busiess rules) about password policy
         //      IUser user = new User(name, password, userType); // Construct a User Object
         foreach (Employee employee in EmployeeList)
         {
             if (employee.employeeNumber > maxId)
             {
                 maxId = employee.employeeNumber;
             }
         }
         IEmployee theEmployee = EmployeeFactory.GetEmployee(title, firstName, middleName, lastName, phoneNumber,
                                                             email, personalAddress, employeeNumber, dateOfBirth, ppsn, wage, employeeCategory,
                                                             employeeCardNumber, hireDate, photo);
         // Using a Factory to create the user entity object. ie seperating object creation from business logic
         EmployeeList.Add(theEmployee);             // Add a reference to the newly created object to the Models UserList
         DataLayer.AddNewEmployeeToDb(theEmployee); //Gets the DataLayer to add the new user to the DB.
         return(true);
     }
     catch (System.Exception excep)
     {
         return(false);
     }
 }