Ejemplo n.º 1
0
        public long CreateExerciseProgram(ProgramInputModel model)
        {
            try
            {
                var program = new Data.Entities.ExerciseProgram
                {
                    Name           = model.Name,
                    Description    = model.Description,
                    DurationInDays = model.LengthInDays,
                    StartDate      = DateTime.Today.Date,
                    CreatedBy      = Environment.UserName,
                    CreateDate     = DateTime.Now
                };

                var programPk = _exerciseProgramRepository.Insert(program);

                var workout = new Workout
                {
                    Profile_Fk         = 1,
                    ExerciseProgram_Fk = (int)programPk,
                    StartDate          = DateTime.Now,
                    EndDate            = DateTime.Today.AddDays(1).AddSeconds(-1),
                    CreatedBy          = Environment.UserName,
                    CreateDate         = DateTime.Now
                };

                _workoutRepository.Insert(workout);

                return(programPk);
            }
            catch (Exception e)
            {
                throw new Exception();
            }
        }
Ejemplo n.º 2
0
        public SubscriberProfileViewModel GetUserProfile()
        {
            var subscriber         = _subscriberRepository.GetById(2);
            var subscriberBodyMass = _subscriberBodyMassRepository.GetAll()
                                     .Where(x => x.Profile_Fk == 2 && (x.EndDate > DateTime.Now || x.EndDate == null))
                                     .OrderByDescending(x => x.CreateDate);

            var weightHistory = new List <WeightHistory>();

            foreach (var entry in subscriberBodyMass)
            {
                var bmi         = Math.Round((703 * (double)entry.WeightInPounds) / ((double)entry.HeightInInches * (double)entry.HeightInInches), 2);
                var bmiCategory = string.Empty;

                if (bmi < 18.5)
                {
                    bmiCategory = "Underweight";
                }
                else if (bmi < 24.9)
                {
                    bmiCategory = "Normal";
                }
                else if (bmi < 29.9)
                {
                    bmiCategory = "Overweight";
                }
                else
                {
                    bmiCategory = "Obese";
                }

                weightHistory.Add(new WeightHistory
                {
                    Id             = entry.BodyMass_Pk,
                    WeightInPounds = entry.WeightInPounds,
                    CreateDate     = entry.CreateDate,
                    Bmi            = bmi,
                    BmiCategory    = bmiCategory
                });
            }

            var dayOfWeek    = (int)DateTime.Today.DayOfWeek;
            var currentWeek  = DateTime.Today.AddDays(-dayOfWeek);
            var currentMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            var currentYear  = new DateTime(DateTime.Today.Year, 1, 1);

            var workoutsCompleted      = _workoutRepository.GetAll().Where(x => x.Complete);
            var workoutsCompletedWeek  = workoutsCompleted.Where(x => x.StartDate > currentWeek).Count();
            var workoutsCompletedMonth = workoutsCompleted.Where(x => x.StartDate > currentMonth).Count();
            var workoutsCompletedYear  = workoutsCompleted.Where(x => x.StartDate > currentYear).Count();

            var todaysWorkout = _workoutRepository.GetAll()
                                .Where(x => x.StartDate <DateTime.Now &&
                                                         x.EndDate> DateTime.Now)
                                .FirstOrDefault();

            var currentExerciseProgram = new Data.Entities.ExerciseProgram();
            var excerciseCount         = 0;

            if (todaysWorkout != null)
            {
                currentExerciseProgram = _exerciseProgramRepository.GetAll()
                                         .Where(x => x.ExerciseProgram_Pk == todaysWorkout.ExerciseProgram_Fk)
                                         .FirstOrDefault();

                if (currentExerciseProgram != null)
                {
                    excerciseCount = _exerciseProgramExerciseRepository.GetAll()
                                     .Where(x => x.ExerciseProgram_Fk == currentExerciseProgram.ExerciseProgram_Pk)
                                     .Count();
                }
            }

            var profile = new SubscriberProfileViewModel
            {
                SubscriberName              = subscriber?.DisplayName ?? string.Empty,
                FirstName                   = subscriber?.FirstName ?? string.Empty,
                LastName                    = subscriber?.LastName ?? string.Empty,
                EmailAddress                = subscriber?.EmailAddress ?? string.Empty,
                DateOfBirth                 = subscriber?.DateOfBirth.Value ?? DateTime.MinValue,
                Height                      = 74,
                BodyMassIndex               = weightHistory?.OrderByDescending(x => x.CreateDate)?.FirstOrDefault()?.Bmi ?? 0,
                Weight                      = weightHistory?.OrderByDescending(x => x.CreateDate)?.FirstOrDefault()?.WeightInPounds ?? 0,
                WeightHistory               = weightHistory ?? new List <WeightHistory>(),
                DateJoined                  = subscriber?.CreateDate ?? DateTime.MinValue,
                CurrentProgramId            = currentExerciseProgram?.ExerciseProgram_Pk ?? 0,
                CurrentWorkoutName          = currentExerciseProgram?.Name ?? string.Empty,
                CurrentWorkoutDescription   = currentExerciseProgram.Description ?? string.Empty,
                IsCurrentProgramCompleted   = todaysWorkout?.Complete ?? false,
                WorkoutsCompletedWeek       = workoutsCompletedWeek,
                WorkoutsCompletedMonth      = workoutsCompletedMonth,
                WorkoutCompletedYear        = workoutsCompletedYear,
                CurrentWorkoutExerciseCount = excerciseCount
            };

            return(profile);
        }