コード例 #1
0
        // GET: Exercises/Details/5
        public async Task <IActionResult> Random()
        {
            List <Exercise> exercises = await _context.Exercises.ToListAsync();

            var random = new Random();
            int index  = random.Next(exercises.Count);

            if (exercises == null)
            {
                return(NotFound());
            }
            Exercise exercise = exercises[index];
            //Get the embed code and start time for the youtube video of the selected exercise
            YoutubeData videoData = parseYoutubeUrl(exercise.Url);

            ViewBag.embedCode        = videoData.videoCode;
            ViewBag.embedTimeSeconds = (videoData.startTimeMillis / 1000).ToString();
            ViewBag.fromRandom       = true;

            return(View("~/Views/Exercises/Details.cshtml", exercise));
        }
コード例 #2
0
        // GET: Exercises/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Exercise exercises = await _context.Exercises
                                 .SingleOrDefaultAsync(m => m.Id == id);

            if (exercises == null)
            {
                return(NotFound());
            }

            //Get the embed code and start time for the youtube video of the selected exercise
            YoutubeData videoData = parseYoutubeUrl(exercises.Url);

            ViewBag.embedCode        = videoData.videoCode;
            ViewBag.embedTimeSeconds = (videoData.startTimeMillis / 1000).ToString();
            ViewBag.fromRandom       = false;

            return(View(exercises));
        }