public IActionResult Edit(string id, SectionType sectionType) { this.ViewData["sectionId"] = id; switch (sectionType) { case SectionType.VideoSection: var model = this.context.VideoSections .Include(s => s.Lesson) .FirstOrDefault(s => s.Id == id); if (model == null) { return(this.NotFound()); } var viewModel = new VideoSectionViewModel() { Name = model.Name, Description = model.Description, SectionType = model.SectionType, Id = model.Id, LessonId = model.LessonId, VideoUrl = model.VideoUrl }; return(this.View("EditVideoSection", viewModel)); } return(this.NotFound()); }
public async Task <IActionResult> CreateVideoSection(VideoSectionViewModel model) { if (this.ModelState.IsValid) { var videoSection = new VideoSection() { VideoUrl = model.VideoUrl, Position = model.Position, Name = model.Name, Description = model.Description, LessonId = model.LessonId }; context.Add(videoSection); await context.SaveChangesAsync(); } return(this.RedirectToAction("Details", "Lessons", new { id = model.LessonId })); }
public async Task <IActionResult> EditVideoSection(string id, VideoSectionViewModel model) { this.logger.LogInformation(id); if (id != model.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var section = this.context.VideoSections.FirstOrDefault(c => c.Id == id); model.LessonId = section.LessonId; section.Name = model.Name; section.Description = model.Description; section.VideoUrl = model.VideoUrl; section.Position = model.Position; context.Update(section); await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!context.VideoSections.Any(c => c.Id == model.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Details", "Lessons", new { id = model.LessonId })); } return(this.NotFound()); }
public IViewComponentResult Invoke() { var videoLessonsViewModel = new VideoSectionViewModel(); return(this.View(videoLessonsViewModel)); }