/// <summary>
        /// Determines whether the objective edit post is valid for processing.
        /// </summary>
        /// <param name="PfNumber">The pf number of the user posting the objective updates.</param>
        /// <param name="UpdateObjective">The objective being updated.</param>
        /// <param name="PerformanceCycleId">The performance cycle identifier.</param>
        /// <returns>Flag indicating whether the objective update post is valid.</returns>
        public bool IsObjectiveEditPostValid(int PfNumber, EditObjective UpdateObjective, int? PerformanceCycleId)
        {
            try
            {
                // Check that the user owns the objective being edited.
                var checkResult = from o in this.db.Objectives
                                  join eo in this.db.EmployeeObjectives on o.Id equals eo.ObjectiveId
                                  join e in this.db.employees on eo.EmployeeId equals e.ID
                                  where e.Code == PfNumber.ToString() && o.Id == UpdateObjective.ObjectiveId && o.CycleId == PerformanceCycleId
                                  select new
                                  {
                                      e.Code,
                                      o.Id,
                                      o.CycleId
                                  };

                if (checkResult != null)
                {
                    // Check that the total weight after edit will not exceed 100%
                    int totalWeight = (from o in this.db.Objectives
                                       join eo in this.db.EmployeeObjectives on o.Id equals eo.ObjectiveId
                                       join c in this.db.PerformanceReviewCycles on o.CycleId equals c.Id
                                       join e in this.db.employees on eo.EmployeeId equals e.ID
                                       where e.Code == PfNumber.ToString() && c.Id == PerformanceCycleId
                                       select (int?)eo.Weight).Sum(x => x.Value);

                    int oldWeight = Int32.Parse((from o in this.db.Objectives
                                                 join eo in this.db.EmployeeObjectives on o.Id equals eo.ObjectiveId
                                                 join c in this.db.PerformanceReviewCycles on o.CycleId equals c.Id
                                                 join e in this.db.employees on eo.EmployeeId equals e.ID
                                                 where e.Code == PfNumber.ToString() && c.Id == PerformanceCycleId && o.Id == UpdateObjective.ObjectiveId
                                                 select eo.Weight).FirstOrDefault().ToString());
                    // subtract the old weight of the objective before checking for the new weight.
                    totalWeight -= oldWeight;

                    if ((totalWeight + UpdateObjective.Weight) <= 100)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    // user doesn't own the objective being updated.
                    return false;
                }
            }
            catch (DataException)
            {
                // Handle exception
                return false;
            }
            catch (Exception)
            {
                // Handle exception
                return false;
            }
        }
        public bool Edit(int? cycle, int empPfNumber, EditObjective objectiveUpdate)
        {
            //
            // Scope that will be used for the edit transaction.
            TransactionScope scope = new TransactionScope();

            try
            {
                using (scope)
                {
                    if (this.objRules.IsPfNumberValid(empPfNumber))
                    {
                        if (this.objRules.IsObjectiveEditPostValid(empPfNumber, objectiveUpdate, cycle))
                        {
                            Objective performanceObjective = new Objective
                            {
                                Id = objectiveUpdate.ObjectiveId,
                                CycleId = objectiveUpdate.CycleId,
                                Title = objectiveUpdate.Objective
                            };
                            this.db.Entry(performanceObjective).State = System.Data.Entity.EntityState.Modified;

                            EmployeeObjective empObjective = new EmployeeObjective
                            {
                                Id = objectiveUpdate.EmployeeObjectiveId,
                                EmployeeId = objectiveUpdate.EmployeeId,
                                ObjectiveId = objectiveUpdate.ObjectiveId,
                                Weight = objectiveUpdate.Weight
                            };
                            this.db.Entry(empObjective).State = System.Data.Entity.EntityState.Modified;

                            this.db.SaveChanges();

                            //
                            // Complete the scope.
                            scope.Complete();
                            //return the operation flag.
                            return true;
                        }
                        else
                        {
                            // Objective edit is invalid.
                            scope.Dispose();
                            return false;
                        }
                    }
                    else
                    {
                        // user making edit is invalid.
                        scope.Dispose();
                        return false;
                    }
                }
            }
            catch (DataException)
            {
                // Handle exception.
                scope.Dispose();
                return false;
            }
            catch (TransactionException)
            {
                // Handle exception.
                scope.Dispose();
                return false;
            }
            catch (Exception)
            {
                // Handle exception.
                scope.Dispose();
                return false;
            }
        }