public void TestGetEmployeeId()
 {
     EmployeeDirectory employee = new EmployeeDirectory();
     int result = employee.GetEmployeeId("51251");
     Assert.IsTrue(result == 1082);
 }
        /// <summary>
        /// Adds the staff performance objective to the repository.
        /// </summary>
        /// <param name="newObjective">The new objective.</param>
        /// <param name="pfNumber">The pf number of staff.</param>
        /// <returns>
        /// Flag indicating whether the objective was successfully a
        /// </returns>
        public bool AddObjective(AddObjective newObjective, int pfNumber)
        {
            // Transaction scope to be used to add new objective.
            TransactionScope scope = new TransactionScope();
            try
            {
                if (this.objRules.IsPfNumberValid(pfNumber))
                {
                    if (this.objRules.IsObjectiveAddPostValid(pfNumber, newObjective.CycleId, newObjective.Weight))
                    {
                        EmployeeDirectory employee = new EmployeeDirectory();
                        int empId = employee.GetEmployeeId(pfNumber.ToString());
                        newObjective.EmployeeId = empId;

                        if (empId != -1)
                        {
                            // Setup transaction scope.
                            using (scope)
                            {
                                //
                                // Add the Objective record to the database.
                                Objective newEmployeeObjective = new Objective
                                {
                                    CycleId = newObjective.CycleId,
                                    Title = newObjective.Objective
                                };
                                this.db.Objectives.Add(newEmployeeObjective);
                                this.db.SaveChanges();

                                //
                                // Add the EmployeeObjective record to the database.
                                newObjective.ObjectiveId = newEmployeeObjective.Id; // Inserted objective record Id

                                EmployeeObjective empObjectiveRecord = new EmployeeObjective
                                {
                                    EmployeeId = newObjective.EmployeeId,
                                    ObjectiveId = newObjective.ObjectiveId,
                                    Weight = newObjective.Weight
                                };
                                this.db.EmployeeObjectives.Add(empObjectiveRecord);
                                this.db.SaveChanges();

                                //
                                // Complete the transaction scope and submit changes.
                                scope.Complete();
                            }
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (DataException)
            {
                //
                // Handle exception.
                scope.Dispose();
                return false;
            }
            catch (Exception)
            {
                //
                // Handle exception.
                scope.Dispose();
                return false;
            }
        }