How to generate the missing dates in a schedule?
<p>I have a schedule that only contains one week of training (31 workouts), and now I need to generate the rest of the workouts until the end of the schedule (eg. 20120601-20120831).
So I thought of maybe loop the workouts and put addDays(7) on all workout.date.</p>

<p>I have tried using foreach and a for, but cant get it to work.</p>

<p>my GenerateSchedule method:</p>

<pre><code>public ActionResult GenerateSchedule(int scheduleId)
    {
        //get schedule included list of 31 workouts
        //only added one week on workouts
        var schedule = _scheduleServices.GetSchedule(scheduleId);
        var workouts = schedule.Workouts.ToList();
        int i = 0;
        for(var day = schedule.FromDate; day.Date &lt;= schedule.ToDate; day =  day.AddDays(1))
        {
            foreach (var workout in workouts)
            {

            }

            var newWorkout = new WorkoutFormModel
            {
                ScheduleId = workouts[i].ScheduleId,
                Date = workouts[i].Date.AddDays(7),
                StartTime = workouts[i].StartTime,
                EndTime = workouts[i].EndTime,
                InstructorId = workouts[i].Instructor.Id,
                CourseId = workouts[i].Course.Id,
            };

            i++;
            _workoutServices.AddWorkout(newWorkout);
        }

        /*
        foreach(var workout in schedule.Workouts)
        {
            if (workout.Date.AddDays(7) &lt;= schedule.ToDate)
            {
                var newWorkout = new WorkoutFormModel
                                     {
                                         ScheduleId = workout.ScheduleId,
                                         Date = workout.Date.AddDays(7),
                                         StartTime = workout.StartTime,
                                         EndTime = workout.EndTime,
                                         InstructorId = workout.Instructor.Id,
                                         CourseId = workout.Course.Id,

                                     };
                _workoutServices.AddWorkout(newWorkout);
            }
        }*/

        return RedirectToAction("Overview", new { scheduleId });
    }
</code></pre>

<p>updated:</p>

<pre><code>    private static List&lt;WorkoutFormModel&gt; ExtendSchedule(Schedule schedule)
    {
        var workoutList = new List&lt;WorkoutFormModel&gt;();

        for (var workoutStart = schedule.FromDate; workoutStart &lt;= schedule.ToDate; workoutStart = workoutStart.AddDays(7))
        {


            workoutList.AddRange(schedule.Workouts.Select(Workout =&gt; new WorkoutFormModel
            {
                ScheduleId = schedule.Id,
                Date = workoutStart.Add(Workout.WeekOffset),
                StartTime = Workout.StartTime,
                EndTime = Workout.EndTime,

                Course = Workout.Course
            }));
        }

        return workoutList;
    }
</code></pre>
