/// <summary> /// This method adds a new Full Time Employee to the database. /// </summary> /// <param name="fName">The first name of the Full Time Employee.</param> /// <param name="lName">The last name of the Full Time Employee.</param> /// <param name="SIN">The Social Insurance Number of the Full Time Employee.</param> /// <param name="dateOfBirth">The Date of Birth of the Full Time Employee.</param> /// <param name="dateOfHire">The Date that the Full Time Employee was hired.</param> /// <param name="dateOfTermination">The Date that the Full Time Employee was terminated.</param> /// <param name="salary">The total amount paid to the Full Time Employee over the course of a year.</param> /// <returns>A bool. true if employee was added, false otherwise.</returns> public static bool AddFulltimeEmployee(string fName, string lName, string SIN, DateTime dateOfBirth, DateTime dateOfHire, DateTime dateOfTermination, double salary) { bool empAdded = false; try { //Check if an employee with that sin number already exists bool employeeExists = FE.Any(x => x.socialInsuranceNumber == SIN); if (employeeExists) { throw new Exception(); //The employee exists, it can't be added } else { FulltimeEmployee emp = new FulltimeEmployee(fName, lName, SIN, dateOfBirth, dateOfHire, dateOfTermination, salary); bool valid = emp.Validate(); if (valid) { FE.Add(emp); Logging logger = new Logging(); logger.Log(lName + ", " + fName + " SIN: " + SIN + " - ADDED", "Employees", "AddFulltimeEmployee"); empAdded = true; } } } catch (Exception) { empAdded = false; } return(empAdded); }
public void FulltimeEmployeeTest_Success() { FulltimeEmployee fullTimeEmp = new FulltimeEmployee("Ronnie", "Skowron", "123456789", DateTime.Parse("2004-08-17"), DateTime.Parse("2006-08-14"), DateTime.Parse("2010-11-12"), 16); bool success = fullTimeEmp.Validate(); Assert.IsTrue(success); }