Example #1
0
        public ActionResult Index()
        {
            var profile = _subscriberProfileService.GetUserProfile();

            if (profile == null)
            {
                profile = new SubscriberProfileViewModel();
            }

            return(View(profile));
        }
        public ActionResult GetProfile()
        {
            var subscriberId = new Guid(User.Identity.GetUserId());

            var subscriber = _subscriberService.GetSubscriber(subscriberId);

            var model = new SubscriberProfileViewModel();

            Mapper.Map(subscriber, model);

            return(View("SubscriberProfile", model));
        }
        public ActionResult UpdateProfile(SubscriberProfileViewModel model)
        {
            UpdateProfileInputModel inputModel = new UpdateProfileInputModel
            {
                Id           = 2,
                Weight       = model.Weight,
                Height       = model.Height,
                EmailAddress = model.EmailAddress,
                DateOfBirth  = model.DateOfBirth.HasValue ? model.DateOfBirth.Value : DateTime.MinValue
            };

            _subscriberProfileService.UpdateUserProfile(inputModel);

            TempData["Saved"] = $"Profile Saved @ {DateTime.Now.ToLongTimeString()}";

            return(Redirect(Request.UrlReferrer.ToString()));
        }
Example #4
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);
        }