我想改變日期到列表中的所有鍛鍊,其他屬性工作正常,只有當我更改日期我得到問題。我嘗試了不同的故障排除,但都沒有奏效。我嘗試使用updatedWorkout.Date作爲workoutStart =超出範圍。如果我使用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的幫助!
設置「日期」字段時會出現什麼問題? – horgh 2012-08-10 01:08:18
有問題的存儲庫是什麼?它是否瞭解身體鍛鍊與Id = old.Id應更新提供的值?因爲我看到你創建新的鍛鍊,而不是更新舊的......這是EntityFramework或L2S(沒有在標籤中指定)? – horgh 2012-08-10 01:11:32
當我通過workoutstart = updatedWorkout.Date設置日期時,我得到一個輸出或範圍。 – n3tx 2012-08-10 07:02:55