Example #1
0
        /// <summary>
        /// Creates the milestone on the system
        /// </summary>
        /// <param name="milestone">The milestone to be created for the goal</param>
        /// <param name="goal">The Goal for which we are creating the milestone</param>
        /// <returns>The goal that was created</returns>
        public Milestone CreateMilestoneForGoal(Milestone milestone, Goal goal)
        {
            //Check this is valid
            if (milestone.Target > goal.Target)
            {
                throw new ArgumentException("The target for this milestone exceeds the target for the goal");
            }
            if (milestone.Target <= 0)
            {
                throw new ArgumentException("The target for this milestone cannot be zero or below");
            }

            IEnumerable <Milestone> currentMilestones = milestoneRepository.GetForGoal(goal.Id);

            if (currentMilestones.Any(currentMilestone => currentMilestone.Target == milestone.Target))
            {
                throw new ArgumentException("This goal already has a milestone for the given target amount");
            }

            return(milestoneRepository.CreateForGoal(milestone, goal.Id));
        }