public async Task <IActionResult> OnPostAsync(CancellationToken cancellationToken) { Course course = new Course(); course = mapper.Map(Model, course); course.CreateDate = DateTime.Now; string imageUploadpath = Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages"); string imgNewFileName = await fileHandler.UploadFileAsync(Model.UploadedImage, imageUploadpath, cancellationToken); fileHandler.CreateImageThumb(Path.Combine(imageUploadpath, imgNewFileName), Path.Combine(imageUploadpath, "CourseImageThumb", imgNewFileName), 80); string videoUploadPath = Path.Combine(hostingEnvironment.WebRootPath, "CourseDemo"); string videoNewFileName = await fileHandler.UploadFileAsync(Model.DemoFile, videoUploadPath, cancellationToken); course.ImageName = imgNewFileName; course.DemoFileName = videoNewFileName; course.Keywordkeys = Model.Keywords.Select(k => new Keyword { Title = k }).ToList(); await courseRepository.AddAsync(course, cancellationToken); return(RedirectToPage("/Admin/CourseManagement/Index")); }
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 })); }