Beispiel #1
0
        private void FillHistoricWeight()
        {
            Random random     = new Random();
            int    currweight = Convert.ToInt32(this.Info.Weight.Number);
            string unit       = this.Info.Weight.Unit;

            for (int i = -400; i < -1; i++)
            {
                Weight weight = new Weight
                {
                    Number = random.Next(currweight - 10, currweight + 10),
                    Date   = DateTime.Today.AddDays(i),
                    Unit   = unit
                };
                WeightHistory.Add(weight);
            }
            Weight w = new Weight
            {
                Number = this.Info.Weight.Number,
                Date   = DateTime.Today.AddDays(0),
                Unit   = unit
            };
            Weight yes = new Weight
            {
                Number = this.Info.Weight.Number,
                Date   = DateTime.Today.AddDays(-1),
                Unit   = unit
            };

            WeightHistory.Add(yes);
            WeightHistory.Add(w);
        }
        public async Task <bool> AddChange(WeightHistory history)
        {
            User user = await _userManager.FindByIdAsync(history.UserId);

            if (user != null)
            {
                WeightHistory old;
                user.Weight = history.Weight;
                await _userManager.UpdateAsync(user);

                try { old = _context.WeightHistories.First(x => x.UserId == history.UserId && x.Date == history.Date); } catch { old = null; }
                if (old != null)
                {
                    old.Weight = history.Weight;
                    _context.WeightHistories.Update(old);
                }
                else
                {
                    await _context.WeightHistories.AddAsync(history);
                }
                await _context.SaveChangesAsync();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        public async void InsertWeightEntry(int weight)
        {
            try
            {
                var recordExist = await GetAllWeightEntries();

                var item = recordExist.Find(x => x.EntryDate == DateTime.Today);

                if (item != null)
                {
                    item.Weight = weight;
                    await whData.Update(item);

                    return;
                }

                var entry = new WeightHistory()
                {
                    EntryDate = DateTime.Today,
                    Weight    = weight
                };

                await whData.Insert(entry);
            }
            catch
            {
                Debug.WriteLine("InsertWeightEntry failed.");
            }
        }
        public async Task <IActionResult> PostUserMetrics(User user, MetricsModel model, UserManager <User> _userManager)
        {
            user.Age    = model.MetricAge;
            user.Height = model.MetricHeight;
            WeightHistory        history = new WeightHistory(user.Id, model.MetricWeight, DateTime.Now.Date);
            WeightHistoryManager manager = new WeightHistoryManager(_context, _userManager);
            await manager.AddChange(history);

            user.Goal       = model.MetricGoal;
            user.MaxPushUps = model.MetricPushUps;
            user.MaxPullUps = model.MetricPullUps;
            user.IsMetrics  = true;


            for (int i = 0; i < model.MetricHealth.Count; i++)
            {
                HealthProblem problem = new HealthProblem(user.Id, model.MetricHealth[i].Problem);

                await _context.HealthProblems.AddAsync(problem);

                await _context.SaveChangesAsync();
            }


            await _userManager.UpdateAsync(user);

            return(new OkResult());
        }
        public async Task <IActionResult> UpdateUserMetrics(User user, UserMetricsUpdateModel UserMetrics, UserManager <User> _userManager)
        {
            user.Name = UserMetrics.Name;
            WeightHistory        history = new WeightHistory(user.Id, UserMetrics.MetricWeight, DateTime.Now.Date);
            WeightHistoryManager manager = new WeightHistoryManager(_context, _userManager);
            await manager.AddChange(history);

            user.Age    = UserMetrics.MetricAge;
            user.Gender = UserMetrics.MetricGender;
            user.Goal   = UserMetrics.MetricGoal;
            user.Height = UserMetrics.MetricHeight;
            for (int i = 0; i < UserMetrics.healthProblems.Count; i++)
            {
                UserMetrics.healthProblems[i].UserId = user.Id;
            }
            await _userManager.UpdateAsync(user);

            await _context.SaveChangesAsync();

            var user_health = _context.HealthProblems.Where(x => x.UserId == user.Id).ToList();

            _context.HealthProblems.RemoveRange(user_health);
            await _context.SaveChangesAsync();

            await _context.HealthProblems.AddRangeAsync(UserMetrics.healthProblems);

            await _context.SaveChangesAsync();

            return(new OkResult());
        }
Beispiel #6
0
 public async void UpdateWeightEntry(WeightHistory entry)
 {
     try
     {
         await whData.Update(entry);
     }
     catch
     {
         Debug.WriteLine("InsertWeightEntry failed.");
     }
 }
        public async Task <IActionResult> WeightChange(WeightHistory history)
        {
            history.Date = DateTime.Now.Date;
            WeightHistoryManager manager = new WeightHistoryManager(_context, _userManager);
            bool result = await manager.AddChange(history);

            if (!result)
            {
                return(new StatusCodeResult(400));
            }
            return(new OkResult());
        }
Beispiel #8
0
        public async Task <IActionResult> WeightChange(WeightHistory history)
        {
            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity());
            }
            var user = await _jwtService.CheckUser(Request.Cookies["JWT"]);

            if (user == null)
            {
                return(Unauthorized());
            }

            return(await _statisticsManager.WeightChange(history));
        }