Exemplo n.º 1
0
        //---------------------------------------------------------------------------------------------

        public async Task <Goal> CreateGoalAsync(int userId,
                                                 string name,
                                                 int periodInHours,
                                                 int frequencyWithinPeriod,
                                                 DateTime startDate)
        {
            await ValidateUserExists(userId);

            ValidateGoalName(name);
            ValidatePeriod(periodInHours);
            ValidateFrequency(frequencyWithinPeriod);

            var goal = new Goal
            {
                Name                  = name,
                UserId                = userId,
                PeriodInHours         = periodInHours,
                FrequencyWithinPeriod = frequencyWithinPeriod,
                StartDate             = startDate
            };

            _goalDb.AddGoal(goal);

            await _goalDb.SaveAsync();

            return(goal);
        }