public async Task <IActionResult> Create([Bind("Id,Title,Description,Indx,CourseChapterId,ContentType,FilePath,Duration,IsFree,IsDownloadable")] CourseChapterContent courseChapterContent, Guid cid, IFormFile myfile) { if (ModelState.IsValid) { courseChapterContent.FilePath = await UserFile.UploadeNewFileAsync(courseChapterContent.FilePath, myfile, _environment.WebRootPath, Properties.Resources.Secured); if (courseChapterContent.ContentType == ContentType.youtube) { int position = courseChapterContent.FilePath.IndexOf("="); courseChapterContent.FilePath = courseChapterContent.FilePath.Substring(position + 1); } courseChapterContent.Description = courseChapterContent.Description.Replace("\n", "<br/>"); courseChapterContent.Id = Guid.NewGuid(); _context.Add(courseChapterContent); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "CourseChapters", new { /* routeValues, for example: */ id = courseChapterContent.CourseChapterId })); } ViewData["CourseChapterId"] = new SelectList(_context.CourseChapters, "Id", "Name", courseChapterContent.CourseChapterId); return(View(courseChapterContent)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Title,Description,Indx,CourseChapterId,ContentType,FilePath,Duration,IsFree,IsDownloadable")] CourseChapterContent courseChapterContent, IFormFile myfile) { if (id != courseChapterContent.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (courseChapterContent.ContentType == ContentType.youtube) { int position = courseChapterContent.FilePath.LastIndexOf("="); courseChapterContent.FilePath = courseChapterContent.FilePath.Substring(position + 1); } if (courseChapterContent.ContentType == ContentType.vimeo) { int position = courseChapterContent.FilePath.LastIndexOf("/"); courseChapterContent.FilePath = courseChapterContent.FilePath.Substring(position + 1); } courseChapterContent.FilePath = await UserFile.UploadeNewFileAsync(courseChapterContent.FilePath, myfile, _environment.WebRootPath, Properties.Resources.ScientificEvent); _context.Update(courseChapterContent); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseChapterContentExists(courseChapterContent.Id)) { return(NotFound()); } else { throw; } } var coursechapter = _context.CourseChapters.Include(c => c.Course).SingleOrDefault(c => c.Id == courseChapterContent.CourseChapterId); return(RedirectToAction("Details", "Courses", new { /* routeValues, for example: */ id = coursechapter.CourseId })); } ViewData["CourseChapterId"] = new SelectList(_context.CourseChapters, "Id", "Name", courseChapterContent.CourseChapterId); return(View(courseChapterContent)); }