Exemplo n.º 1
0
        public ActionResult AddWeight(WeightViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Weight", viewModel));
            }

            Metric w = Metric.CreateMetric(User.Identity.GetUserId(), Infrastructure.enums.MetricType.Weight, viewModel.GetRecordedDateTime(), viewModel.Weight, true); _unitOfWork.Metrics.AddOrUpdateMetric(w);

            _unitOfWork.Metrics.AddOrUpdateMetric(w);

            if (viewModel.Bodyfat != null)
            {
                Metric bf = Metric.CreateMetric(User.Identity.GetUserId(), Infrastructure.enums.MetricType.BodyFat, viewModel.GetRecordedDateTime(), viewModel.Bodyfat.Value, true);
                _unitOfWork.Metrics.AddOrUpdateMetric(bf);
            }

            _unitOfWork.Complete();

            // as weight details have changed we need to refresh weights recorded against activities
            ActivityWeight aw = new ActivityWeight(User.Identity.GetUserId());

            aw.UpdateActivityWeight();

            if (viewModel.MoveOntoNextDay)
            {
                WeightViewModel vm = new WeightViewModel(viewModel.GetRecordedDateTime().AddDays(1));
                vm.MoveOntoNextDay = true;
                return(RedirectToAction("Weight", vm));
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
        public ActionResult AddHRV(HRVViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("HRV", viewModel));
            }

            Metric m1 = Metric.CreateMetric(User.Identity.GetUserId(), MetricType.HRV, viewModel.GetRecordedDateTime(), viewModel.HRV.Value, true);

            _unitOfWork.Metrics.AddOrUpdateMetric(m1);

            if (viewModel.HRVReadiness.HasValue)
            {
                Metric m2 = Metric.CreateMetric(User.Identity.GetUserId(), MetricType.HRVReadiness, viewModel.GetRecordedDateTime(), viewModel.HRVReadiness.Value, true);
                _unitOfWork.Metrics.AddOrUpdateMetric(m2);
            }
            if (viewModel.HRVRMSSD.HasValue)
            {
                Metric m3 = Metric.CreateMetric(User.Identity.GetUserId(), MetricType.HRVRMSSD, viewModel.GetRecordedDateTime(), viewModel.HRVRMSSD.Value, true);
                _unitOfWork.Metrics.AddOrUpdateMetric(m3);
            }
            if (viewModel.HRVLnRMSSD.HasValue)
            {
                Metric m4 = Metric.CreateMetric(User.Identity.GetUserId(), MetricType.HRVLnRMSSD, viewModel.GetRecordedDateTime(), viewModel.HRVLnRMSSD.Value, true);
                _unitOfWork.Metrics.AddOrUpdateMetric(m4);
            }
            if (viewModel.HRVSDNN.HasValue)
            {
                Metric m5 = Metric.CreateMetric(User.Identity.GetUserId(), MetricType.HRVSDNN, viewModel.GetRecordedDateTime(), viewModel.HRVSDNN.Value, true);
                _unitOfWork.Metrics.AddOrUpdateMetric(m5);
            }
            if (viewModel.HRVNN50.HasValue)
            {
                Metric m6 = Metric.CreateMetric(User.Identity.GetUserId(), MetricType.HRVNN50, viewModel.GetRecordedDateTime(), viewModel.HRVNN50.Value, true);
                _unitOfWork.Metrics.AddOrUpdateMetric(m6);
            }
            if (viewModel.HRVPNN50.HasValue)
            {
                Metric m7 = Metric.CreateMetric(User.Identity.GetUserId(), MetricType.HRVPNN50, viewModel.GetRecordedDateTime(), viewModel.HRVPNN50.Value, true);
                _unitOfWork.Metrics.AddOrUpdateMetric(m7);
            }

            _unitOfWork.Complete();

            if (viewModel.MoveOntoNextDay)
            {
                HRVViewModel vm = new HRVViewModel(viewModel.GetRecordedDateTime().AddDays(1));
                vm.MoveOntoNextDay = true;
                return(RedirectToAction("HRV", vm));
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 3
0
        private void SaveSeries(TimeSeriesResourceType type, TimeSeriesDataList fitbitData)
        {
            var           metricType             = MetricTypeConversion.FromFitBitType(type);
            List <Metric> currentlyStoredMetrics = _unitOfWork.CRUDRepository.GetByUserId <Metric>(_userId)
                                                   .Where(m => m.MetricType == metricType)
                                                   .ToList();

            foreach (Fitbit.Models.TimeSeriesDataList.Data item in fitbitData.DataList)
            {
                // no value so ignore
                if (string.IsNullOrEmpty(item.Value))
                {
                    continue;
                }

                decimal convertedValue = FitbitConversion.ConvertFitbitValue(type, item.Value);

                // 0 = no value for the type/date so ignore
                if (convertedValue == FitbitConversion.InvalidValue)
                {
                    continue;
                }

                // check if we already have a metric for the given date.
                var existingMetric = currentlyStoredMetrics.Where(m => m.Recorded == item.DateTime).FirstOrDefault();

                if (existingMetric == null)
                {
                    // add metric
                    _unitOfWork.Metrics.AddMetric(Metric.CreateMetric(_userId, metricType, item.DateTime, convertedValue, false));
                }
                else
                {
                    // don't overwrite any manually entered metrics.
                    if (!existingMetric.IsManual)
                    {
                        existingMetric.Value = convertedValue;
                        _unitOfWork.Metrics.UpdateMetric(existingMetric);
                    }
                }
            }
            _unitOfWork.Complete();
        }
Exemplo n.º 4
0
        public ActionResult AddHeartRate(HeartRateViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("HeartRate", viewModel));
            }

            Metric heartRate = Metric.CreateMetric(User.Identity.GetUserId(), Infrastructure.enums.MetricType.RestingHeartRate, viewModel.GetRecordedDateTime(), viewModel.RestingHeartRate, true);

            _unitOfWork.Metrics.AddOrUpdateMetric(heartRate);

            _unitOfWork.Complete();

            if (viewModel.MoveOntoNextDay)
            {
                HeartRateViewModel vm = new HeartRateViewModel(viewModel.GetRecordedDateTime().AddDays(1));
                vm.MoveOntoNextDay = true;
                return(RedirectToAction("HeartRate", vm));
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 5
0
        public ActionResult AddSleep(SleepViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Sleep", viewModel));
            }

            Metric sleep = Metric.CreateMetric(User.Identity.GetUserId(), Infrastructure.enums.MetricType.SleepMinutes, viewModel.GetRecordedDateTime(), viewModel.GetSleepMinutes(), true);

            _unitOfWork.Metrics.AddOrUpdateMetric(sleep);

            _unitOfWork.Complete();

            if (viewModel.MoveOntoNextDay)
            {
                SleepViewModel vm = new SleepViewModel(viewModel.GetRecordedDateTime().AddDays(1));
                vm.MoveOntoNextDay = true;
                return(RedirectToAction("Sleep", vm));
            }

            return(RedirectToAction("Index", "Home"));
        }