public void SyncSpeakers(String eventId) //pk { var allSpeakers = _speakerRepository.GetByPk(eventId); var sessions = _sessionRepository.GetAllEntries(eventId).ToList(); // for each session, update speaker's name for (int i = 0; i < sessions.Count(); i++) { var session = sessions[i]; if (string.IsNullOrWhiteSpace(session.Speakers)) { sessions[i].Speakers = null; } else { var relatedSpeakers = new List <RelatedSpeaker>(); var relatedSpeakersOld = JsonConvert.DeserializeObject <List <string> >(session.Speakers); foreach (var speakerId in relatedSpeakersOld) { relatedSpeakers.Add(new RelatedSpeaker { Id = speakerId, Name = allSpeakers.FirstOrDefault(x => x.SpeakerId == speakerId).Name }); } sessions[i].Speakers = JsonConvert.SerializeObject(relatedSpeakers); } } // remove the line below to persist data: //_sessionRepository.MergeEntities(sessions); }
public IEnumerable <SpeakerViewModel> Get(String eventId) //pk { return(_speakerRepository.GetByPk(eventId)); }