private List <SupplementCycleEntry> getDayDosages(SupplementCycleDefinition definition, int currentDay, SupplementCycle cycle) { var trainingDays = !string.IsNullOrEmpty(cycle.TrainingDays) ? cycle.TrainingDays.Split(',').Select(x => TrainingDayItem.Create(x)).ToList() : new List <TrainingDayItem>(); var newDate = cycle.StartDate.AddDays(currentDay); int week = (int)((newDate - cycle.StartDate).TotalDays / 7) + 1; List <SupplementCycleEntry> dosages = new List <SupplementCycleEntry>(); foreach (var day in definition.Weeks) { if (week >= day.CycleWeekStart && week <= day.CycleWeekEnd) { foreach (var dosage in day.Dosages) { if (dosage.Repetitions == BodyArchitect.Model.SupplementCycleDayRepetitions.EveryDay) { dosages.Add(dosage); continue; } if (dosage.Repetitions == BodyArchitect.Model.SupplementCycleDayRepetitions.OnceAWeek && newDate.DayOfWeek == cycle.StartDate.DayOfWeek) { dosages.Add(dosage); continue; } if (dosage.Repetitions == BodyArchitect.Model.SupplementCycleDayRepetitions.StrengthTrainingDay && trainingDays.Where(x => x.Day == newDate.DayOfWeek && (x.TrainingType == SupplementsCycleTrainingType.Strength || x.TrainingType == SupplementsCycleTrainingType.Both)).Count() > 0) { dosages.Add(dosage); continue; } if (dosage.Repetitions == BodyArchitect.Model.SupplementCycleDayRepetitions.CardioTrainingDay && trainingDays.Where(x => x.Day == newDate.DayOfWeek && (x.TrainingType == SupplementsCycleTrainingType.Cardio || x.TrainingType == SupplementsCycleTrainingType.Both)).Count() > 0) { dosages.Add(dosage); continue; } if (dosage.Repetitions == BodyArchitect.Model.SupplementCycleDayRepetitions.NonTrainingDay && trainingDays.Where(x => x.Day == newDate.DayOfWeek).Count() == 0) { dosages.Add(dosage); continue; } } } } return(dosages); }
public static TrainingDayItem Create(string dayString) { TrainingDayItem item = new TrainingDayItem(); item.Day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayString.Substring(0, 1)); switch (dayString.Substring(1, 1)) { case "B": item.TrainingType = SupplementsCycleTrainingType.Both; break; case "C": item.TrainingType = SupplementsCycleTrainingType.Cardio; break; default: item.TrainingType = SupplementsCycleTrainingType.Strength; break; } return(item); }