public async Task OnGetAsync(int Id, int CourseId, CancellationToken cancellationToken) { CourseEpisod episod = await courseEpisodRepository.GetByIdAsync(Id, cancellationToken); ViewData["CourseId"] = CourseId; //Create video path string videoUploadPath = Path.Combine(hostingEnvironment.WebRootPath, "CourseDemo", "EpisodVideo", episod.FileName); //Delete Old video Path fileHandler.DeleteOldImageThumb(videoUploadPath, string.Empty); //Delete Old Big Thumbnail fileHandler.DeleteOldImageThumb(Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages", "BigEpisodThump", episod.FileName.ChangeExtension(".jpg")), string.Empty); //Delete Old Main Thumbnail fileHandler.DeleteOldImageThumb(Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages", "MainEpisodThump", episod.FileName.ChangeExtension(".jpg")), string.Empty); await courseEpisodRepository.DeleteAsync(episod, cancellationToken); }
public async Task <IActionResult> OnPostAsync(CancellationToken cancellationToken) { CourseEpisod episod = await courseEpisodRepository.GetByIdAsync(Model.Id, cancellationToken); episod.Title = Model.Title; episod.IsFree = Model.IsFree; episod.CourseId = Model.CourseId; if (Assert.NotNull(Model.FormFile)) { //Save video string videoUploadPath = Path.Combine(hostingEnvironment.WebRootPath, "CourseDemo", "EpisodVideo"); string videoNewFileName = await fileHandler.UploadFileAsync(Model.FormFile, videoUploadPath, cancellationToken, Path.Combine(videoUploadPath, episod.FileName)); //Delete Old video Path fileHandler.DeleteOldImageThumb(Path.Combine(videoUploadPath, episod.FileName), string.Empty); //Delete Old Big Thumbnail fileHandler.DeleteOldImageThumb(Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages", "BigEpisodThump", episod.FileName.ChangeExtension(".jpg")), string.Empty); //Delete Old Main Thumbnail fileHandler.DeleteOldImageThumb(Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages", "MainEpisodThump", episod.FileName.ChangeExtension(".jpg")), string.Empty); //Create Big Thumbnail Path From Video & Create Thumbnail Path string outPutPath = Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages", "BigEpisodThump", videoNewFileName.ChangeExtension(".jpg")); string videofilepath = Path.Combine(videoUploadPath, videoNewFileName); FileInformation fileinfo = await fileHandler.GetThumonailFromVideoAsync(videofilepath, outPutPath, cancellationToken); //Create Main Thumbnail string SaveThumnailPath = Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages", "MainEpisodThump", videoNewFileName.ChangeExtension(".jpg")); fileHandler.CreateImageThumb(outPutPath, SaveThumnailPath, 90); episod.EpisodeTime = fileinfo.MetaData.Duration; episod.FileName = videoNewFileName; } await courseEpisodRepository.UpdateAsync(episod, cancellationToken); return(RedirectToPage("/Admin/EpisodManagement/Index", new { Model.CourseId })); }
public async Task <IActionResult> OnPostAsync(CancellationToken cancellationToken) { CourseEpisod episod = new CourseEpisod { IsFree = Model.IsFree, Title = Model.Title }; //Save File string videoUploadPath = Path.Combine(hostingEnvironment.WebRootPath, "CourseDemo", "EpisodVideo"); string videoNewFileName = await fileHandler.UploadFileAsync(Model.FormFile, videoUploadPath, cancellationToken); //Create Thumbnail Path var videofilepath = Path.Combine(videoUploadPath, videoNewFileName); string outPutPath = Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages", "BigEpisodThump", videoNewFileName.ChangeExtension(".jpg")); //Create Thumbnail Path From Video FileInformation fileinfo = await fileHandler.GetThumonailFromVideoAsync(videofilepath, outPutPath, cancellationToken); string SaveThumnailPath = Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages", "MainEpisodThump", videoNewFileName.ChangeExtension(".jpg")); fileHandler.CreateImageThumb(outPutPath, SaveThumnailPath, 90); fileHandler.DeleteOldImageThumb(outPutPath, string.Empty); episod.EpisodeTime = fileinfo.MetaData.Duration; episod.FileName = videoNewFileName; Course course = await courseRepository.GetByIdAsync(Model.CourseId, cancellationToken); course.TotalEpisodTime += episod.EpisodeTime; episod.Course = course; episod.CourseId = course.Id; await courseEpisodRepository.AddAsync(episod, cancellationToken); return(RedirectToPage("/Admin/EpisodManagement/Index", new { Model.CourseId })); }
public async Task <IActionResult> OnPostAsync(CancellationToken cancellationToken) { Course course = await courseRepository.GetByIdAsync(Model.Id, cancellationToken); course = mapper.Map(Model, course); course.CreateDate = course.CreateDate; course.UpdateDate = DateTime.Now; if (Assert.NotNull(Model.UploadedImage)) { string imageUploadpath = Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages"); string imgNewFileName = await fileHandler.UploadFileAsync(Model.UploadedImage, imageUploadpath, cancellationToken, $"{imageUploadpath}\\{Model.ImageName}"); fileHandler.DeleteOldImageThumb($"{imageUploadpath}\\CourseImageThumb\\{Model.ImageName}", Model.ImageName); fileHandler.CreateImageThumb(Path.Combine(imageUploadpath, imgNewFileName), Path.Combine(imageUploadpath, "CourseImageThumb", imgNewFileName), 120); course.ImageName = imgNewFileName; } if (Assert.NotNull(Model.DemoFile)) { string videoUploadPath = Path.Combine(hostingEnvironment.WebRootPath, "CourseDemo"); string videoNewFileName = await fileHandler.UploadFileAsync(Model.DemoFile, videoUploadPath, cancellationToken, $"{videoUploadPath}\\{Model.ImageName}"); course.DemoFileName = videoNewFileName; } course.Keywordkeys = Model.Keywords.Select(k => new Keyword { Title = k }).ToList(); await courseRepository.UpdateAsync(course, cancellationToken); return(RedirectToPage("/Admin/CourseManagement/Index")); }