public IActionResult Video(int taskId)
        {
            var user = _userData.GetUserWithStats(User.GetUserId());

            var task = _taskData.GetVideoTask(taskId);

            VideoTaskStatistic currentStat = null;

            foreach (var stat in user.CourseStatistics)
            {
                foreach (var videoTaskStatistic in stat.VideoTaskStatistics)
                {
                    if (videoTaskStatistic.TaskId == taskId)
                    {
                        currentStat = videoTaskStatistic;
                        break;
                    }
                }
            }

            if (currentStat != null)
            {
                currentStat.IsComplete = true;
                _statisticData.UpdateVideoTaskStatistic(currentStat);
                return(Ok());
            }

            return(NotFound());
        }
        public IActionResult CheckCompleteVideo(int taskId)
        {
            var user = _userData.GetUserWithStats(User.GetUserId());
            VideoTaskStatistic currentStat = null;

            foreach (var stat in user.CourseStatistics)
            {
                foreach (var videoTaskStatistic in stat.VideoTaskStatistics)
                {
                    if (videoTaskStatistic.TaskId == taskId)
                    {
                        currentStat = videoTaskStatistic;
                        break;
                    }
                }
            }

            if (currentStat != null)
            {
                return(Ok(new { isCompleted = currentStat.IsComplete, currentTime = currentStat.CurrentTime }));
            }

            return(NotFound());
        }
Esempio n. 3
0
 public void UpdateVideoTaskStatistic(VideoTaskStatistic model)
 {
     _context.VideoTaskStatistic.Update(model);
     _context.SaveChanges();
 }