Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,user_id,create_time,height,weight,age,waist,bfp")] BodyAbility bodyAbility)
        {
            if (id != bodyAbility.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bodyAbility);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BodyAbilityExists(bodyAbility.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bodyAbility));
        }
Ejemplo n.º 2
0
 public BodyList()
 {
     alllist  = new List <BodyAbility>();
     lastlist = new BodyAbility();
     time     = new List <string>();
     bfp      = new List <string>();
     bmi      = new List <string>();
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("user_id,height,weight,age,waist,")] BodyAbility bodyAbility)
        {
            bodyAbility.create_time = DateTime.Now;
            //计算体脂率的公式
            bodyAbility.bfp = (double)(bodyAbility.waist * 0.74 - (bodyAbility.weight * 0.082 + 44.74)) / bodyAbility.weight;
            bodyAbility.bfp = bodyAbility.bfp * 100;
            //计算BMI的公式
            bodyAbility.bmi = (double)bodyAbility.weight / (bodyAbility.height * bodyAbility.height);
            _context.Add(bodyAbility);
            await _context.SaveChangesAsync();

            result res = new result();

            //系统建议的代码,仿照这个代码,在别的类中,同样的位置,试着自己编写
            res.ans = "";
            if (res.bfp < 15)
            {
                res.ans += "您的体脂率比较低,建议多摄入脂肪;";
            }
            else if (res.bfp >= 15 && res.bfp <= 18)
            {
                res.ans += "您的体脂率正常";
            }
            else
            {
                res.ans += "您的体脂率过高,注意多锻炼";
            }

            if (res.bmi < 18.5)
            {
                res.ans += "您的BMI指数偏低,需要多锻炼身体";
            }
            else if (res.bmi >= 18.5 && res.bmi < 23.9)
            {
                res.ans += "您的BMI指数正常";
            }
            else
            {
                res.ans += "您的BMI指数偏高,需要多锻炼";
            }

            res.bfp = bodyAbility.bfp;
            res.bmi = bodyAbility.bmi;
            JsonResult result = Json(res);


            return(result);
        }