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());
        }
示例#2
0
        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();
        }
示例#3
0
        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;
        }
示例#4
0
 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();
 }
示例#5
0
 partial void DeleteTrainingPlan(TrainingPlan instance);
示例#6
0
 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();
 }
示例#7
0
 partial void UpdateTrainingPlan(TrainingPlan instance);
示例#8
0
 partial void InsertTrainingPlan(TrainingPlan instance);
示例#9
0
 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;
 }
示例#10
0
 public TrainingPlan Build()
 {
     var plan = new TrainingPlan {Goal = new Goal(), ID = _ID};
     return plan;
 }
示例#11
0
        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);
        }