コード例 #1
0
        public async Task <IActionResult> EditTarget(float TargetWeight, DateTime TargetDate)
        {
            if (TargetWeight <= 0 || TargetWeight >= 200 || TargetDate <= DateTime.Today)
            {
                return(BadRequest());
            }

            FitnessUser currentUser = await GetUser();


            BodyweightTarget newTarget = await storageService.GetBodyweightTarget(currentUser);

            if (newTarget == null)
            {
                newTarget = new BodyweightTarget()
                {
                    User = currentUser
                };
            }
            newTarget.TargetWeight = TargetWeight;
            newTarget.TargetDate   = TargetDate;
            await storageService.StoreBodyweightTarget(newTarget);

            return(RedirectToAction("Summary"));
        }
コード例 #2
0
        public async Task <IActionResult> EditTarget()
        {
            FitnessUser currentUser = await GetUser();

            BodyweightTarget target = await storageService.GetBodyweightTarget(currentUser);

            return(View(target));
        }
コード例 #3
0
        public async Task <IActionResult> Summary()
        {
            FitnessUser currentUser = await GetUser();

            IEnumerable <BodyweightRecord> records = await storageService.GetBodyweightRecords(currentUser);

            BodyweightTarget target = await storageService.GetBodyweightTarget(currentUser);

            BodyweightSummaryViewModel viewModel = new BodyweightSummaryViewModel(records, target);

            return(View(viewModel));
        }
コード例 #4
0
        public async Task StoreBodyweightTarget(BodyweightTarget Target)
        {
            if (Target.ID == 0)
            {
                dbContext.BodyweightTargets.Add(Target);
            }
            else
            {
                dbContext.BodyweightTargets.Update(Target);
            }

            await dbContext.SaveChangesAsync();
        }
コード例 #5
0
        public BodyweightSummaryViewModel(IEnumerable <BodyweightRecord> AllRecords, BodyweightTarget Target)
        {
            if (AllRecords == null || AllRecords.Count() == 0)
            {
                return;
            }

            this.AllRecords       = AllRecords;
            this.Target           = Target;
            this.MostRecentRecord = AllRecords.First();

            CurrentMonthRecords = AllRecords.Where(record => record.Date >= DateTime.Today.AddDays(-28));
            CurrentWeekRecords  = CurrentMonthRecords.Where(record => record.Date >= DateTime.Today.AddDays(-7));

            if (CurrentWeekRecords.Count() != 0)
            {
                CurrentWeekProgress = CurrentWeekRecords.First().Weight - CurrentWeekRecords.Last().Weight;
                CurrentWeekAverage  = CurrentWeekProgress / 7;
            }

            if (CurrentMonthRecords.Count() != 0)
            {
                CurrentMonthProgress = CurrentMonthRecords.First().Weight - CurrentMonthRecords.Last().Weight;
                CurrentMonthAverage  = CurrentMonthProgress / 28;
            }

            if (AllRecords.Count() != 0)
            {
                AllTimeProgress = AllRecords.First().Weight - AllRecords.Last().Weight;
                AllTimeAverage  = AllTimeProgress / ((float)(AllRecords.First().Date - AllRecords.Last().Date).TotalDays) * 7;
            }

            if (Target == null)
            {
                return;
            }

            DistanceToTarget     = Target.TargetWeight - MostRecentRecord.Weight;
            DailyProgressNeeded  = (float)(DistanceToTarget / (Target.TargetDate - DateTime.Today).TotalDays);
            WeeklyProgressNeeded = DailyProgressNeeded * 7;
        }
コード例 #6
0
        public async Task <BodyweightTarget> GetBodyweightTarget(FitnessUser User)
        {
            BodyweightTarget result = await dbContext.BodyweightTargets.FirstOrDefaultAsync(target => target.User == User);

            return(result);
        }