Exemplo n.º 1
0
        /// <summary>
        /// Attempts to save the goal on the system
        /// and returns the value stored in the database
        /// </summary>
        /// <param name="userId">The User ID</param>
        /// <param name="goal">The goal to be persisted</param>
        /// <returns>The goal that was saved on the system</returns>
        public Goal CreateGoal(int?userId, Goal goal)
        {
            //Ensure we have valid data
            if (!userId.HasValue)
            {
                throw new ArgumentOutOfRangeException(nameof(userId), "Please ensure the user is given when creating the goal");
            }
            if (goal.Id > 0)
            {
                throw new ArgumentOutOfRangeException(nameof(goal.Id), "Please ensure the goal has no identifying information when creating");
            }

            //Create the goal
            Goal savedGoal = goalRepository.CreateGoalForUser(userId.Value, goal);

            return(savedGoal);
        }