public async Task <IActionResult> Edit(int id, [Bind("ID,user_id,create_time,age,gunhurdle_time,gunhurdle_score,threeoffroad_time,threeoffroad_score,twohurdle_time,twohurdle_score,threehurdle_time,threehurdle_score")] ComtrainAbilities comtrainAbilities)
        {
            if (id != comtrainAbilities.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(comtrainAbilities);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComtrainAbilitiesExists(comtrainAbilities.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(comtrainAbilities));
        }
        public async Task <IActionResult> Create([Bind("ID,user_id,create_time,age,gunhurdle_time,gunhurdle_score,threeoffroad_time,threeoffroad_score,twohurdle_time,twohurdle_score,threehurdle_time,threehurdle_score,score")] ComtrainAbilities comtrainAbilities, string type)
        {
            comtrainAbilities.create_time = DateTime.Now;
            var s = await _context.Gunhurdle_Score.SingleOrDefaultAsync(m => m.age == comtrainAbilities.age && m.num == comtrainAbilities.gunhurdle_time);

            comtrainAbilities.gunhurdle_score = s.score * 20 + 40;
            var s2 = await _context.Threeoffroad_Score.SingleOrDefaultAsync(m => m.age == comtrainAbilities.age && m.num == comtrainAbilities.threeoffroad_time);

            comtrainAbilities.threeoffroad_score = s2.score * 20 + 40;
            var s3 = await _context.Threehurdle_Score.SingleOrDefaultAsync(m => m.age == comtrainAbilities.age && m.num == comtrainAbilities.threehurdle_time);

            comtrainAbilities.threehurdle_score = s3.score * 20 + 40;
            var s4 = await _context.Twohurdle_Score.SingleOrDefaultAsync(m => m.age == comtrainAbilities.age && m.num == comtrainAbilities.twohurdle_time);

            comtrainAbilities.twohurdle_score = s4.score * 20 + 40;

            comtrainAbilities.score = (comtrainAbilities.gunhurdle_score + comtrainAbilities.threehurdle_score
                                       + comtrainAbilities.threehurdle_score + comtrainAbilities.twohurdle_score) / 4;

            if (type == "yes")
            {
                _context.Add(comtrainAbilities);
                await _context.SaveChangesAsync();
            }

            Result res = new Result();

            res.gunhurdlescore    = comtrainAbilities.gunhurdle_score.ToString();
            res.threehurdlescore  = comtrainAbilities.threehurdle_score.ToString();
            res.twohurdlescore    = comtrainAbilities.twohurdle_score.ToString();
            res.threeoffroadscore = comtrainAbilities.threeoffroad_score.ToString();

            JsonResult result = Json(res);

            return(result);
        }