コード例 #1
0
        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);
        }
コード例 #2
0
 public IEnumerable <SpeakerViewModel> Get(String eventId) //pk
 {
     return(_speakerRepository.GetByPk(eventId));
 }