Beispiel #1
0
        public ExerciseBlock GetNextEnabledExercise(Random random = null, bool overrideDifferent = false)
        {
            ExerciseBlock nextExercise;

            if (MostRecentExercises.Any() && !overrideDifferent)
            {
                nextExercise = GetNextDifferentEnabledExercise(MostRecentExercises.First(), random);
            }
            else
            {
                var exercises        = GetExerciseBlocks();
                var enabledExercises = exercises.Where(e => e.Enabled).ToList();

                if (enabledExercises.Count == 0)
                {
                    return(null);
                }

                var index = (random ?? new Random()).Next(0, enabledExercises.Count);

                nextExercise = enabledExercises[Min(index, enabledExercises.Count - 1)];
            }
            MostRecentExercises.Delete(_ => true);
            if (nextExercise != null)
            {
                _db.Insert(MostRecentExercise.FromBlock(nextExercise));
            }
            return(nextExercise);
        }
Beispiel #2
0
        private ExerciseBlock GetNextDifferentEnabledExercise(MostRecentExercise mostRecentExercise, Random random = null)
        {
            var exercises        = GetExerciseBlocks();
            var enabledExercises = exercises.Where(e => e.Enabled);
            // Look at name and quantitiy instead of Id since users can create multiple blocks that are the same
            var differentEnabledExercises = enabledExercises.Where(e =>
                                                                   !e.CombinedName.Equals(mostRecentExercise.CombinedName, StringComparison.CurrentCultureIgnoreCase) ||
                                                                   (e.CombinedName.Equals(mostRecentExercise.CombinedName, StringComparison.CurrentCultureIgnoreCase) &&
                                                                    e.Quantity != mostRecentExercise.Quantity))
                                            .ToList();

            // If there are no different exercises, see if there are any available at all
            if (differentEnabledExercises.Count == 0)
            {
                return(GetNextEnabledExercise(random, true));
            }

            var index = (random ?? new Random()).Next(0, differentEnabledExercises.Count);

            return(differentEnabledExercises[Min(index, differentEnabledExercises.Count - 1)]);
        }