public void SaveBackground(IFormFile file, int sceneId) { Scene scene = _sceneService.GetScene(sceneId); if (scene != null) { if (file.ContentType.StartsWith("image/")) { byte[] p1 = null; using (var fs1 = file.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } VRBackground background = new VRBackground() { Img = p1, Colour = "#FFFFFF", SceneId = sceneId, }; if (_VRBackgroundRepository.getBackgroundWithSceneId(sceneId) != null) { _VRBackgroundRepository.UpdateBackground(background); } else { _VRBackgroundRepository.AddBackground(background); } } } }
public IActionResult UploadBackgroundImage(IFormFile file, int sceneId) { // If the file isn't null if (file != null && file.Length > 0 && file.ContentType.StartsWith("image/")) { _VRBackgroundService.SaveBackground(file, sceneId); } // get the scene with sceneId var scene = _sceneService.GetScene(sceneId); var scenes = _sceneService.GetScenesWithCourseId(scene.CourseId); int index = scenes.ToList().IndexOf(scene); return(RedirectToAction("SceneEditor", "SceneEditor", new { courseId = scene.CourseId, selectedIndex = index })); }