public IActionResult DownloadFile(int episodeId) { var episode = _courseSerervice.GetEpisodeById(episodeId); string filepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/courseFiles", episode.EpisodeFileName); string fileName = episode.EpisodeFileName; if (episode.IsFree) { byte[] file = System.IO.File.ReadAllBytes(filepath); return(File(file, "application/force-download", fileName)); } if (User.Identity.IsAuthenticated) { if (_orderService.isUserInCourse(User.Identity.Name, episode.CourseId)) { byte[] file = System.IO.File.ReadAllBytes(filepath); return(File(file, "application/force-download", fileName)); } } return(Forbid()); }
public void OnGet(int id) { CourseEpisode = _courseSerervice.GetEpisodeById(id); ViewData["CourseId"] = CourseEpisode.CourseId; }