public async Task <IActionResult> Edit(int id, [Bind("Id,Topic")] SpeakerTopic speakerTopic) { if (id != speakerTopic.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(speakerTopic); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SpeakerTopicExists(speakerTopic.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(speakerTopic)); }
public async Task <IActionResult> Create([Bind("Id,Topic")] SpeakerTopic speakerTopic) { if (ModelState.IsValid) { _context.Add(speakerTopic); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(speakerTopic)); }
UpdateSpeakers(Sacrament sacrament, String[] selectedSpeakers, String[] SpeakerTopic) { GetMembersForDropdown(); ICollection <Speakers> selectedSpeakersList = new List <Speakers>(); ICollection <Speakers> allSpeakers = _context.Speakers .Include(s => s.Member).ToList(); ICollection <SpeakerTopic> allTopics = _context.SpeakerTopic.ToList(); //_context.Member.find if (selectedSpeakers[0] != null) { for (int i = 0; i < selectedSpeakers.Length; i++) { Member mem = await getMember(selectedSpeakers[i]); SpeakerTopic top = getTopic(SpeakerTopic[i]); if (mem != null) { selectedSpeakersList.Add(new Speakers { Sacrament = sacrament, Member = mem, Topic = top }); } //Remove old speaker references. foreach (var aSpeak in allSpeakers) { if (aSpeak != null && sacrament.Speakers != null && sacrament.Speakers.Contains(aSpeak)) { sacrament.Speakers.Remove(aSpeak); } } if (sacrament.Speakers == null) { sacrament.Speakers = new List <Speakers>(); } //Add new speaker references (If Not Exist) foreach (var speaker in selectedSpeakersList) { sacrament.Speakers.Add(speaker); } //_context.SaveChanges(); } } }
private SpeakerTopic getTopic(string v) { if (v == null || v == "") { return(null); } SpeakerTopic top; if (_context.SpeakerTopic.Any(T => T.Topic == v && v.Trim() != "")) { top = _context.SpeakerTopic.SingleOrDefault(T => T.Topic == v.Trim()); //mem.Topic = top; } else { top = new SpeakerTopic(); top.Topic = v.Trim(); _context.Add(top); _context.SaveChanges(); //mem.Topic = top; } return(top); }