public async Task OnGetAsync(int Id, int CourseId, CancellationToken cancellationToken) { Model.CourseId = CourseId; CourseEpisod result = await courseEpisodRepository.GetByIdAsync(Id, cancellationToken); Model.IsFree = result.IsFree; Model.Title = result.Title; Model.FileName = result.FileName; Model.Id = result.Id; }
public async Task <IActionResult> DownloadFile(int EpisodId, CancellationToken cancellationToken) { CourseEpisod selectedEpisod = await courseEpisodRepository.GetByIdAsync(EpisodId, cancellationToken); string filepath = Path.Combine(hostingEnvironment.WebRootPath, "CourseDemo", "EpisodVideo", selectedEpisod.FileName); if (selectedEpisod.IsFree) { byte[] file = System.IO.File.ReadAllBytes(filepath); return(File(file, "application/force-download", selectedEpisod.FileName)); } if (User.Identity.IsAuthenticated) { if (orderRepository.IsBuyByUser(Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value), selectedEpisod.CourseId)) { byte[] file = System.IO.File.ReadAllBytes(filepath); return(File(file, "application/force-download", selectedEpisod.FileName)); } } TempData["Message"] = "ابتدا باید دوره را خریداری کنید"; return(Redirect($"/Course/Detail?CourseId={selectedEpisod.CourseId}")); }
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); }