コード例 #1
0
        public async Task <IActionResult> Dashboard()
        {
            // Get current user
            var currentuser = await GetCurrentUserAsync();

            bool isUserAdmin = await _userManager.IsInRoleAsync(currentuser, "Admin");

            List <int>           courseIds = new List <int>();
            IEnumerable <Course> courses   = new List <Course>();

            // If user isn't admin, return only courses assigned the them
            if (!isUserAdmin)
            {
                IEnumerable <CourseUserRelation> courseUserRelations = _courseUserRelationService.GetCourseUserRelationsWithUserId(currentuser.Id);

                foreach (CourseUserRelation r in courseUserRelations)
                {
                    courseIds.Add(r.CourseId);
                }
                courses = _courseService.GetCoursesWithCourseIds(courseIds);
            }
            else
            {// If user is admin, return all courses under their account
                courses = _courseService.GetCoursesWithCustomerId(currentuser.CustomerId);
                foreach (Course c in courses)
                {
                    courseIds.Add(c.Id);
                }
            }

            List <VRBackground> tempBackgrounds = new List <VRBackground>();

            // get first scene of each course
            // get image from each scene
            List <Scene> firstScenes = new List <Scene>();

            foreach (int i in courseIds)
            {
                firstScenes.Add(_sceneService.GetScenesWithCourseId(i).ElementAt(0));
            }
            foreach (Scene s in firstScenes)
            {
                // for each scene, store the background in tempBackgrounds
                tempBackgrounds.Add(_VRBackgroundService.getBackgroundImageObjectWithSceneId(s.Id));
            }

            IEnumerable <VRBackground> BackgroundImages = tempBackgrounds;

            DashboardViewModel viewModel = new DashboardViewModel()
            {
                Courses = courses,
                Images  = BackgroundImages,
            };

            return(View(viewModel));
        }
コード例 #2
0
        public IActionResult SceneEditor(int courseId, int selectedIndex)
        {
            SceneEditorViewModel         viewModel;
            IEnumerable <Scene>          scenes          = _sceneService.GetScenesWithCourseId(courseId);
            IEnumerable <VRObject>       vRObjects       = new List <VRObject>();
            IEnumerable <VRHotspot>      vRHotspots      = new List <VRHotspot>();
            IEnumerable <VRQuestionCard> vRQuestionCards = new List <VRQuestionCard>();
            List <int> sceneIds = new List <int>();

            viewModel = new SceneEditorViewModel()
            {
                CourseId          = courseId,
                AddSceneViewModel = new AddSceneViewModel(),
            };

            if (scenes != null)
            {
                if (scenes.Count() > 0)
                {
                    if (_VRObjectService.GetVROBjectsWithSceneId(scenes.ElementAt(selectedIndex).Id) != null)
                    {
                        // If there are vr objects in the scene, return them
                        vRObjects = _VRObjectService.GetVROBjectsWithSceneId(scenes.ElementAt(selectedIndex).Id);
                    }
                    if (_VRObjectService.GetVRHotspotsWithSceneId(scenes.ElementAt(selectedIndex).Id) != null)
                    {
                        // If there are vrHotSpot objects in the scene, return them
                        vRHotspots = _VRObjectService.GetVRHotspotsWithSceneId(scenes.ElementAt(selectedIndex).Id);
                    }
                    if (_VRObjectService.GetVRQuestionsWithSceneId(scenes.ElementAt(selectedIndex).Id) != null)
                    {
                        // If there are vr Question objects in the scene, return them
                        vRQuestionCards = _VRObjectService.GetVRQuestionsWithSceneId(scenes.ElementAt(selectedIndex).Id);
                    }
                }
                // Return the scenes for the existing scenes component
                foreach (Scene scene in scenes)
                {
                    sceneIds.Add(scene.Id);
                }

                viewModel.Scenes        = scenes;
                viewModel.SelectedScene = 0;

                IEnumerable <VRBackground> Backgrounds = _VRBackgroundService.getBackgroundImagesWithSceneIds(sceneIds);

                if (vRObjects != null && vRObjects.Count() != 0)
                {
                    viewModel.VRObjects = vRObjects;
                }
                if (vRHotspots != null && vRHotspots.Count() != 0)
                {
                    viewModel.VRHotspots = vRHotspots;
                }
                if (vRQuestionCards != null && vRQuestionCards.Count() != 0)
                {
                    var responses = getResponsesWithQuestionCards(vRQuestionCards);

                    if (responses != null)
                    {
                        if (responses.Count() > 0)
                        {
                            viewModel.Responses = responses;
                        }
                    }

                    viewModel.VRQuestionCards = vRQuestionCards;
                }
                if (selectedIndex > 0)
                {
                    viewModel.SelectedScene = selectedIndex;
                }
                if (Backgrounds != null)
                {
                    viewModel.Backgrounds = Backgrounds;
                }
            }
            return(View(viewModel));
        }
コード例 #3
0
        public async Task <IActionResult> Export(int courseId)
        {
            // Get the course to be exported
            Course course = _courseService.GetCourse(courseId);

            // Create export directory under the courses ID
            CreateExportDirectory(course.Id);

            // Get all scenes under the course
            IEnumerable <Scene> scenes = _sceneService.GetScenesWithCourseId(courseId);

            // Set the scene index to 0
            int sceneIndex = 0;

            // cycle through each scene
            foreach (Scene item in scenes)
            {
                // Get all the vr Objects in the scene
                IEnumerable <VRObject> vRObjects = _VRObjectService.GetVROBjectsWithSceneId(item.Id);

                // for each vr object, if it's video or audio, find the file in the MEDIA folder and move it to the scorm content folder
                foreach (VRObject v in vRObjects)
                {
                    if (v.ObjectType == "VideoObject" || v.ObjectType == "AudioObject")
                    {
                        MoveMediaFileToScormContentFolder(v.ObjectType, v.Value, courseId);
                    }
                }

                // Getting all the hotspot, question and responses in the scene
                IEnumerable <VRHotspot>          vRHotspots      = _VRObjectService.GetVRHotspotsWithSceneId(item.Id);
                IEnumerable <VRQuestionCard>     vRQuestionCards = _VRObjectService.GetVRQuestionsWithSceneId(item.Id);
                IEnumerable <VRQuestionResponse> tempResponses   = new List <VRQuestionResponse>();
                List <VRQuestionResponse>        responses       = new List <VRQuestionResponse>();

                if (vRQuestionCards != null && vRQuestionCards.Count() > 0)
                {
                    foreach (VRQuestionCard q in vRQuestionCards)
                    {
                        // stores the individual question's responses in temp responses
                        // This is reset each iteration of the foreach loop
                        tempResponses = _VRObjectService.GetVRQuestionresponsesWithQuestionId(q.Id);
                        foreach (VRQuestionResponse r in tempResponses)
                        {
                            // iterate through the tempResponses to add the response to the responses to be exported
                            responses.Add(r);
                        }
                    }
                }
                // Get the current scenes background image
                VRBackground Image = _VRBackgroundService.getBackgroundImageObjectWithSceneId(item.Id);

                // Export Model to be passed to export.cshtml
                ExportModel eModel = new ExportModel()
                {
                    backgroundImage     = Image,
                    VRObjects           = vRObjects,
                    VRHotSpots          = vRHotspots,
                    VRQuestionCards     = vRQuestionCards,
                    VRQuestionResponses = responses
                };

                // Returns a string of the Export.cshtml after it has been populated with the above data
                string exportView = await this.RenderViewToStringAsync("/Views/Export/Export.cshtml", eModel);

                // Writes the above data to a html file for each scene
                WriteToFile(exportView, item.CourseId, sceneIndex);
                sceneIndex++;
            }

            // once the loop is complete, zip it as per the xAPI standard wrapper docs
            ZipScorm(course.Id);

            // Relocate from the ZIPS to be downloaded by the user
            FileStreamResult fileStreamResult = null;

            try
            {
                string     path            = "C:/OPT/ZIPS/" + courseId + ".zip";
                FileStream fileStreamInput = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Delete);
                fileStreamResult = new FileStreamResult(fileStreamInput, "APPLICATION/octet-stream");
                fileStreamResult.FileDownloadName = "yourScorm.zip";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                // Ensure the zip is always deleted so the course can be downlaoded multiple times
                DeleteExportedZip(course.Id);
            }

            return(fileStreamResult);
        }