public void AssertInsertPlannedRuns() { var builder = new AthleteBuilder(); var athlete = builder.Build(); var selectedDays = WeekdaySelectionEnumeration.FifthDayOfWeek | WeekdaySelectionEnumeration.SeventhDayOfWeek; var trainingPlan = new TrainingPlan { Workload = 50, Goal = CreateGoal(), Athlete = athlete, Start = new DateTime(2009, 1, 1), StartDistance = 2000, PreferredWeekdays = (int)selectedDays }; MemoryDataContext.Clear(); Assert.IsTrue(MemoryDataContext.IsEmpty); MemoryDataContext.InsertOnSubmit(athlete); MemoryDataContext.InsertOnSubmit(trainingPlan); MemoryDataContext.Commit(); var runDataAccess = new RunDataAccess(); runDataAccess.CreateRuns(trainingPlan); Assert.AreEqual(47, MemoryDataContext.Queryable<Run>().Count()); }
public void CreateRuns(TrainingPlan trainingPlan) { var existingPlan = _dataContext.GetExisting(trainingPlan); var existingAthlete = _dataContext.GetExisting(trainingPlan.Athlete); DeleteFuturePlannedRuns(existingPlan); var trainer = new Trainer(); var runs = trainer.CreateRuns(existingAthlete, existingPlan); foreach (var run in runs) { run.Athlete = existingAthlete; run.TrainingPlan = existingPlan; run.LastChanged = DateTime.Now; _dataContext.InsertOnSubmit(run); } _dataContext.Commit(); }
public TrainingPlan SaveTrainingPlan(TrainingPlan trainingPlan) { DataContext.RollbackAndAttach(trainingPlan.Athlete); trainingPlan.Goal.Athlete = trainingPlan.Athlete; if (trainingPlan.ID > 0) { DataContext.UpdateAndAttach(trainingPlan.Goal); DataContext.UpdateAndAttach(trainingPlan); } else { DataContext.InsertOnSubmit(trainingPlan); } DataContext.Commit(); var runDataAccess = new RunDataAccess(DataContext); runDataAccess.CreateRuns(trainingPlan); return trainingPlan; }
public List<Run> GetPlannedRuns(TrainingPlan trainingPlan) { if (trainingPlan.ID <= 0) { throw new InvalidOperationException("trainingPlan.ID <= 0"); } if (trainingPlan.Athlete == null) { throw new InvalidOperationException("trainingPlan.Athlete == null"); } return GetRuns(trainingPlan.Athlete).Where(x => x.TrainingPlanID == trainingPlan.ID).ToList(); }
partial void DeleteTrainingPlan(TrainingPlan instance);
private void DeleteFuturePlannedRuns(TrainingPlan trainingPlan) { var runs = _dataContext.Queryable<Run>().Where( x => x.TrainingPlan.ID == trainingPlan.ID && x.Start >= trainingPlan.Start); foreach (var run in runs) { _dataContext.DeleteOnSubmit(run); } _dataContext.Commit(); }
partial void UpdateTrainingPlan(TrainingPlan instance);
partial void InsertTrainingPlan(TrainingPlan instance);
private static TrainingPlan CreatePlan(Athlete athlete, WeekdaySelectionEnumeration trainingDays) { var trainingPlan = new TrainingPlan { Workload = 50, Goal = CreateGoal(), Athlete = athlete, Start = new DateTime(2009, 1, 1), StartDistance = 2000, PreferredWeekdays = (int) trainingDays }; return trainingPlan; }
public TrainingPlan Build() { var plan = new TrainingPlan {Goal = new Goal(), ID = _ID}; return plan; }
public IEnumerable<Run> CreateRuns(Athlete athlete, TrainingPlan plan) { TrainingPlan = plan; Athlete = athlete; plan.EnsureIsValid(); var workload = Convert.ToDouble(plan.Workload) / 100; WeeklyProgression *= workload; var goaledSequencer = BuildSequencer(); return CreateRuns(plan.DaysAsWeekdaySelectionEnumeration(), goaledSequencer); }