Example #1
0
        /// <summary>
        /// Generates the milestones on the system for the given
        /// goal (if none exist), equally spaced to the target
        /// </summary>
        /// <param name="goal">The Goal for which we are creating the milestones</param>
        /// <returns>The milestones that were created</returns>
        public IEnumerable <Milestone> GenerateMilestones(Goal goal)
        {
            //If we have some we should stop
            IEnumerable <Milestone> currentMilestones = milestoneRepository.GetForGoal(goal.Id);

            if (currentMilestones.Any())
            {
                throw new Exception("This goal has milestones already - cannot automatically create additional milestones");
            }

            List <Milestone> milestones  = new List <Milestone>(5);
            double           targetSteps = goal.Target / 5;

            for (int i = 1; i <= 5; i++)
            {
                milestones.Add(new Milestone(targetSteps * i, $"{goal.Name} - {i}/5 completed!", null));
            }

            //Generate the milestones
            milestones = ExecuteThenOrderBy(() => milestoneRepository.CreateMultipleForGoal(milestones, goal.Id), m => m.Id).ToList();
            return(milestones);
        }