public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,Visible,Start,Stop,CourseId")] Lecture lecture) { if (id != lecture.Id) { return(NotFound()); } var lectureWithOwner = await _context.Lectures.Where(x => x.Course.Owner.Id == GetUserId() && x.Id == id) .SingleOrDefaultAsync(); if (lectureWithOwner == null) { return(Forbid()); } if (ModelState.IsValid) { lectureWithOwner.Title = lecture.Title; lectureWithOwner.Description = lecture.Description; lectureWithOwner.Visible = lecture.Visible; try { _context.Update(lectureWithOwner); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LectureExists(lectureWithOwner.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(lecture)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,Archived")] Course course) { if (id != course.Id) { return(NotFound()); } var courseWithOwner = await _context.Courses.Where(x => x.Owner.Id == GetUserId() && x.Id == id).SingleOrDefaultAsync(); if (courseWithOwner == null) { return(Forbid()); } if (ModelState.IsValid) { courseWithOwner.Title = course.Title; courseWithOwner.Description = course.Description; courseWithOwner.Archived = course.Archived; try { _context.Update(courseWithOwner); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(course.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(course)); }