public AssignmentPageV3VM AssignmentCompleted(AssignmentPageV3VM model)
        {
            var a = context.UserProgress.FirstOrDefault
                        (x => x.CourseId == model.CourseId && x.UserId == model.UserId);

            if (a.CourseFinishedId == true)
            {
                a.CourseFinishedId = false;
            }
            else
            {
                a.CourseFinishedId = true;
            }

            context.UserProgress.Update(a);
            context.SaveChanges();

            AssignmentPageV3VM b = new AssignmentPageV3VM();

            b            = model;
            b.FinishedId = a.CourseFinishedId;

            var finished           = GetFinishedCourses((b.UserId).GetValueOrDefault());
            var courseCount        = GetAllAssignments().Count;
            var progressbar        = (double)finished / (double)courseCount;
            var progressbarpercent = progressbar * 100;

            b.ProgressbarValue = progressbarpercent;

            return(b);
        }
        public IActionResult AssignmentPageV3(int id, CourseFrontPageVM cfpmodel)
        {
            List <Courses> courses = assignmentrepository.GetAllAssignments();

            cfpmodel.Courses = courses;

            var             courseModel        = assignmentrepository.GetAssignmentById(id);
            ClaimsPrincipal currentUser        = User;
            var             aspNetUserId       = _userManager.GetUserId(User);
            var             userId             = assignmentrepository.GetUserIdByAspNetId(aspNetUserId);
            var             username           = assignmentrepository.GetUserNameByAspNetId(aspNetUserId);
            var             finishedId         = assignmentrepository.GetCourseFinishedId(userId, courseModel.Id);
            var             instructions       = assignmentrepository.GetInstructions(courseModel.Id);
            var             solutions          = assignmentrepository.GetSolutions(courseModel.Id);
            var             exerciseid         = assignmentrepository.GetExerciseId(courseModel.Id);
            var             tipsid             = assignmentrepository.GetTipsId(exerciseid);
            var             tipinfo            = assignmentrepository.GetTipInfos(tipsid);
            var             urls               = assignmentrepository.GetUrls(courseModel.Id);
            var             linkinfos          = assignmentrepository.GetLinkInfos(courseModel.Id);
            var             finishedcourses    = assignmentrepository.GetFinishedCourses(userId);
            var             progressbar        = (double)finishedcourses / (double)courses.Count;
            var             progressbarpercent = progressbar * 100;

            AssignmentPageV3VM model = new AssignmentPageV3VM
            {
                Name             = courseModel.Name,
                Description      = courseModel.Description,
                UserId           = userId,
                UserName         = username,
                CourseId         = courseModel.Id,
                FinishedId       = finishedId,
                Instructions     = instructions,
                Solutions        = solutions,
                TipInfos         = tipinfo,
                Urls             = urls,
                LinkInfos        = linkinfos,
                ProgressbarValue = progressbarpercent
            };

            return(View(model));
        }
        public IActionResult AssignmentPageV3(AssignmentPageV3VM model)
        {
            var statusChangedModel = assignmentrepository.AssignmentCompleted(model);

            return(View(statusChangedModel));
        }