リスト内のすべてのワークアウトの日付を変更しようとしていますが、他のプロパティは正常に機能していますが、日付を変更した場合にのみ問題が発生します。さまざまなトラブルシューティングを試みましたが、どれもうまくいきませんでした。updatedWorkout.Date を運動開始 = 範囲外として使用してみました。old.Date を使用する場合、7 日単位で新しい日付を追加するにはどうすればよいですか?
多分これを行うためのより良い方法がありますか?
これが私の方法です:
private int UpdateForAllWorkouts(IWorkoutCommand updatedWorkout)
{
try
{ // get schedule
var schedule = _scheduleRepository.GetIncludeWorkouts(updatedWorkout.ScheduleId);
// get workouts within the schedule by schedule id
var workout = schedule.Workouts.FirstOrDefault(w => w.Id == updatedWorkout.Id);
for (var workoutStart = workout.Date; workoutStart <= schedule.ToDate; workoutStart = workoutStart.AddDays(7))
{
// get specdfic workout by workout id and start time
var old = schedule.Workouts.Single(w => w.Date == workoutStart && w.StartTime == workout.StartTime);
var tmp = new Model.Workout
{
Id = old.Id,
CourseId = updatedWorkout.CourseId,
InstructorId = updatedWorkout.InstructorId,
Date = //<---problem
StartTime = updatedWorkout.StartTime,
EndTime = updatedWorkout.EndTime,
ScheduleId = updatedWorkout.ScheduleId,
WeekOffSet = updatedWorkout.WeekOffSet.Days
};
}
return updatedWorkout.Id;
}
catch (Exception ex)
{
throw new Exception("");
}
}
助けてくれてthx!