public IActionResult addVideo(string sel, string sel1, string title, string text, string link) { var newFileName = string.Empty; if (HttpContext.Request.Form.Files != null) { var fileName = string.Empty; string PathDB = string.Empty; var files = HttpContext.Request.Form.Files; foreach (var file in files) { if (file.Length > 0) { //Getting FileName fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); //Assigning Unique Filename (Guid) var myUniqueFileName = Convert.ToString(Guid.NewGuid()); //Getting file Extension var FileExtension = Path.GetExtension(fileName); // concating FileName + FileExtension newFileName = myUniqueFileName + FileExtension; // Combines two strings into a path. fileName = Path.Combine(_environment.WebRootPath, "Files1") + $@"\{newFileName}"; // if you want to store path of folder in database PathDB = "Files1/" + newFileName; using (FileStream fs = System.IO.File.Create(fileName)) { file.CopyTo(fs); fs.Flush(); } /* FileModel m = new FileModel { Path = PathDB }; * a.Add(m); * a.SaveChanges();*/ /* Course c = new Course { CourseImage = PathDB, CourseTitle = title, CourseDescription = shortt }; * db.Courses.Add(c); * db.SaveChanges();*/ VideoBg bg = new VideoBg { CourseId = int.Parse(sel), LevelId = int.Parse(sel1), VideoTitle = title, VideoText = text, VideoImg = PathDB, Link = link }; db.VideoBgs.Add(bg); db.SaveChanges(); } } } return(Redirect("Video")); }
public IActionResult Page(int id) { VideoBg c = db.VideoBgs.FirstOrDefault(x => x.VideoId == id); List <VideoBg> v = db.VideoBgs.Where(x => x.CourseId == c.CourseId).ToList(); List <Level> l = db.Levels.Where(x => x.CourseId == c.CourseId).ToList(); ViewBag.obj = c; ViewData["level"] = l; ViewData["video"] = v; return(View("pagecourse")); }