Exemplo n.º 1
0
        public async Task <ActionResult> Approve(int?id)
        {
            if (!CurrentUser.HasAccess(UserAccess.CourseVerify) &&
                !CurrentUser.HasAccess(UserAccess.CourseApproval1) &&
                !CurrentUser.HasAccess(UserAccess.CourseApproval2) &&
                !CurrentUser.HasAccess(UserAccess.CourseApproval3))
            {
                return(new HttpUnauthorizedResult());
            }

            var model = await CoursesController.TryGetFrontCourse(id.Value);

            model.Description = HttpUtility.HtmlDecode(model.Description);
            model.Objectives  = HttpUtility.HtmlDecode(model.Objectives);

            if (model == null)
            {
                TempData["ErrorMessage"] = "No such course.";

                return(RedirectToAction("Index", "Courses"));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Post(ContentCompletionModel model)
        {
            bool CanViewAsLearner = false;

            if (CurrentUser.HasAccess(UserAccess.CourseCreate) || CurrentUser.HasAccess(UserAccess.CourseEdit) ||
                CurrentUser.HasAccess(UserAccess.CourseVerify) || CurrentUser.HasAccess(UserAccess.CourseApproval1) ||
                CurrentUser.HasAccess(UserAccess.CourseApproval2) || CurrentUser.HasAccess(UserAccess.CourseApproval3) ||
                CurrentUser.HasAccess(UserAccess.CourseDiscussionCreate))
            {
                CanViewAsLearner = true;
            }

            if (ModelState.IsValid)
            {
                model.UserId = CurrentUser.UserId.Value;

                var response = await WepApiMethod.SendApiAsync <ContentCompletionModel>(HttpVerbs.Post, ContentCompletionsApiUrl.Post + $"?CanViewAsLearner={CanViewAsLearner}", model);

                if (response.isSuccess)
                {
                    //TempData["SuccessMessage"] = "Content Completed";

                    await LogActivity(Modules.Learning, $"User : {CurrentUser?.Name} complete this content : {model.Title}");

                    var nextContent = response.Data.nextContentId;
                    var nextModule  = response.Data.nextModuleId;
                    var courseId    = response.Data.CourseId;

                    if (nextContent == null)
                    {
                        if (nextModule == null) // No more module and content, lets go to the course page
                        {
                            TempData["SuccessMessage"] = "Congratulations, you have completed this course.";

                            var course = await CoursesController.TryGetFrontCourse(courseId.Value);

                            if (course.Status != Model.eLearning.CourseStatus.Published)
                            {
                                if (CurrentUser.HasAccess(UserAccess.CourseCreate))
                                {
                                    return(RedirectToAction("Content", "Courses", new { area = "eLearning", @id = courseId }));
                                }
                                else
                                if (CurrentUser.HasAccess(UserAccess.CourseNonLearnerView))
                                {
                                    return(RedirectToAction("Approve", "CourseApprovals", new { area = "eLearning", @id = courseId }));
                                }
                            }
                            else
                            if (course.Status == Model.eLearning.CourseStatus.Published)
                            {
                                if (CurrentUser.HasAccess(UserAccess.CourseCreate))
                                {
                                    return(RedirectToAction("Content", "Courses", new { area = "eLearning", @id = courseId }));
                                }
                                else
                                if (CurrentUser.HasAccess(UserAccess.CourseNonLearnerView))
                                {
                                    return(RedirectToAction("Content", "Courses", new { area = "eLearning", @id = courseId }));
                                }
                                else
                                {
                                    return(RedirectToAction("View", "Courses", new { area = "eLearning", @id = courseId }));
                                }
                            }
                            return(RedirectToAction("View", "Courses", new { area = "eLearning", @id = courseId }));
                        }
                        else  // go to next module
                        {
                            return(RedirectToAction("View", "CourseModules", new { area = "eLearning", @id = nextModule.Value }));
                        }
                    }
                    else // go to next content
                    {
                        return(RedirectToAction("View", "CourseContents", new { area = "eLearning", @id = nextContent.Value }));
                    }
                }
            }
            TempData["ErrorMessage"] = "Cannot complete content.";

            return(RedirectToAction("Content", "CourseModules", new { area = "eLearning", @id = model.CourseModuleId }));
        }