我想改变日期到列表中的所有锻炼,其他属性工作正常,只有当我更改日期我得到问题。我尝试了不同的故障排除,但都没有奏效。我尝试使用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