public async Task <IActionResult> Edit(int id, [Bind("ID,Date,Conducting,OpeningHymn,Invocation,SacramentHymn,SacramentPrayer,ClosingHymn,Benediction,Speakers")] MeetingView meeting) { if (id != meeting.ID) { return(NotFound()); } if (ModelState.IsValid) { try { Meeting newMeeting = new Meeting { ID = meeting.ID, Date = meeting.Date, Conducting = meeting.Conducting, OpeningHymn = meeting.OpeningHymn, Invocation = meeting.Invocation, SacramentHymn = meeting.SacramentHymn, SacramentPrayer = meeting.SacramentPrayer, ClosingHymn = meeting.ClosingHymn, Benediction = meeting.Benediction }; _context.Update(newMeeting); await _context.SaveChangesAsync(); //Remove Speakers var removeSpeakers = _context.Speakers.Select(s => s).Where(s => s.MeetingID == id); foreach (Speaker s in removeSpeakers) { _context.Remove(s); } await _context.SaveChangesAsync(); //Update Speakers foreach (Speaker s in meeting.Speakers) { s.MeetingID = id; _context.Speakers.Add(s); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MeetingExists(meeting.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(meeting)); }