public async Task <ActionResult <ConferenceDTO.SpeakerResponse> > PostSpeaker(ConferenceDTO.Speaker input) { var speaker = new Speaker { Name = input.Name, WebSite = input.WebSite, Bio = input.Bio }; _db.Speakers.Add(speaker); await _db.SaveChangesAsync(); var result = speaker.MapSpeakerResponse(); return(CreatedAtAction(nameof(GetSpeaker), new { id = speaker.ID }, result)); }
public override async Task LoadDataAsync(Stream fileStream, ApplicationDbContext db) { // var blah = new RootObject().rooms[0].sessions[0].speakers[0].name; var addedSpeakers = new Dictionary <string, Speaker>(); var addedTracks = new Dictionary <string, Track>(); var array = await JToken.LoadAsync(new JsonTextReader(new StreamReader(fileStream))); var root = array.ToObject <List <RootObject> >(); foreach (var date in root) { foreach (var room in date.rooms) { if (!addedTracks.ContainsKey(room.name)) { var thisTrack = new Track { Name = room.name }; db.Tracks.Add(thisTrack); addedTracks.Add(thisTrack.Name, thisTrack); } foreach (var thisSession in room.sessions) { foreach (var speaker in thisSession.speakers) { if (!addedSpeakers.ContainsKey(speaker.name)) { var thisSpeaker = new Speaker { Name = speaker.name }; db.Speakers.Add(thisSpeaker); addedSpeakers.Add(thisSpeaker.Name, thisSpeaker); } } var session = new Session { Title = thisSession.title, StartTime = thisSession.startsAt, EndTime = thisSession.endsAt, Track = addedTracks[room.name], Abstract = thisSession.description }; session.SessionSpeakers = new List <SessionSpeaker>(); foreach (var sp in thisSession.speakers) { session.SessionSpeakers.Add(new SessionSpeaker { Session = session, Speaker = addedSpeakers[sp.name] }); } db.Sessions.Add(session); } } } }
public override async Task <Conference> LoadDataAsync(string conferenceName, Stream fileStream) { //var blah = new RootObject().rooms[0].sessions[0].speakers[0].name; var addedSpeakers = new Dictionary <string, Speaker>(); var addedTracks = new Dictionary <string, Track>(); var addedTags = new Dictionary <string, Tag>(); var array = await JToken.LoadAsync(new JsonTextReader(new StreamReader(fileStream))); var conference = new Conference { Name = conferenceName }; var root = array.ToObject <List <RootObject> >(); foreach (var date in root) { foreach (var room in date.rooms) { if (!addedTracks.ContainsKey(room.name)) { var thisTrack = new Track { Name = room.name }; conference.Tracks.Add(thisTrack); addedTracks.Add(thisTrack.Name, thisTrack); } foreach (var thisSession in room.sessions) { foreach (var speaker in thisSession.speakers) { if (!addedSpeakers.ContainsKey(speaker.name)) { var thisSpeaker = new Speaker { Name = speaker.name }; addedSpeakers.Add(thisSpeaker.Name, thisSpeaker); } } foreach (var category in thisSession.categories) { if (!addedTags.ContainsKey(category.name)) { var thisTag = new Tag { Name = category.name }; addedTags.Add(thisTag.Name, thisTag); } } var session = new Session { Conference = conference, Title = thisSession.title, StartTime = thisSession.startsAt, EndTime = thisSession.endsAt, Track = addedTracks[room.name], Abstract = thisSession.description, }; session.SessionTags = thisSession.categories.Select(c => new SessionTag { Session = session, Tag = addedTags[c.name] }).ToList(); session.SessionSpeakers = thisSession.speakers.Select(s => new SessionSpeaker { Session = session, Speaker = addedSpeakers[s.name] }).ToList(); conference.Sessions.Add(session); } } } conference.StartTime = conference.Sessions.Min(s => s.StartTime); conference.EndTime = conference.Sessions.Max(s => s.EndTime); return(conference); }
public override async Task LoadDataAsync(Stream fileStream, ApplicationDbContext db) { var reader = new JsonTextReader(new StreamReader(fileStream)); var speakerNames = new Dictionary <string, Speaker>(); var tracks = new Dictionary <string, Track>(); JArray doc = await JArray.LoadAsync(reader); foreach (JObject item in doc) { var theseSpeakers = new List <Speaker>(); foreach (var thisSpeakerName in item["speakerNames"]) { if (!speakerNames.ContainsKey(thisSpeakerName.Value <string>())) { var thisSpeaker = new Speaker { Name = thisSpeakerName.Value <string>() }; db.Speakers.Add(thisSpeaker); speakerNames.Add(thisSpeakerName.Value <string>(), thisSpeaker); Console.WriteLine(thisSpeakerName.Value <string>()); } theseSpeakers.Add(speakerNames[thisSpeakerName.Value <string>()]); } var theseTracks = new List <Track>(); foreach (var thisTrackName in item["trackNames"]) { if (!tracks.ContainsKey(thisTrackName.Value <string>())) { var thisTrack = new Track { Name = thisTrackName.Value <string>() }; db.Tracks.Add(thisTrack); tracks.Add(thisTrackName.Value <string>(), thisTrack); } theseTracks.Add(tracks[thisTrackName.Value <string>()]); } var session = new Session { Title = item["title"].Value <string>(), StartTime = item["startTime"].Value <DateTime>(), EndTime = item["endTime"].Value <DateTime>(), Track = theseTracks[0], Abstract = item["abstract"].Value <string>() }; session.SessionSpeakers = new List <SessionSpeaker>(); foreach (var sp in theseSpeakers) { session.SessionSpeakers.Add(new SessionSpeaker { Session = session, Speaker = sp }); } db.Sessions.Add(session); } }
protected override void LoadFormattedData(ApplicationDbContext db) { string json = File.ReadAllText(Filename); //var blah = new RootObject().rooms[0].sessions[0].speakers[0].name; var addedSpeakers = new Dictionary <string, Speaker>(); var addedTracks = new Dictionary <string, Track>(); var addedTags = new Dictionary <string, Tag>(); var root = JsonConvert.DeserializeObject <List <RootObject> >(json); foreach (var date in root) { foreach (var room in date.rooms) { if (!addedTracks.ContainsKey(room.name)) { var thisTrack = new Track { Name = room.name, Conference = this.Conference }; db.Tracks.Add(thisTrack); addedTracks.Add(thisTrack.Name, thisTrack); } foreach (var thisSession in room.sessions) { foreach (var speaker in thisSession.speakers) { if (!addedSpeakers.ContainsKey(speaker.name)) { var thisSpeaker = new Speaker { Name = speaker.name }; db.Speakers.Add(thisSpeaker); addedSpeakers.Add(thisSpeaker.Name, thisSpeaker); Console.WriteLine(thisSpeaker.Name); } } foreach (var category in thisSession.categories) { if (!addedTags.ContainsKey(category.name)) { var thisTag = new Tag { Name = category.name }; db.Tags.Add(thisTag); addedTags.Add(thisTag.Name, thisTag); Console.WriteLine(thisTag.Name); } } var session = new Session { Conference = Conference, Title = thisSession.title, StartTime = thisSession.startsAt, EndTime = thisSession.endsAt, Track = addedTracks[room.name], Abstract = thisSession.description }; session.SessionSpeakers = new List <SessionSpeaker>(); foreach (var sp in thisSession.speakers) { session.SessionSpeakers.Add(new SessionSpeaker { Session = session, Speaker = addedSpeakers[sp.name] }); } db.Sessions.Add(session); } } } }