public static Song Add(SrfPlayListContext context, Songlog songlog, Artist artist) { var song = context.Songs.Local.FirstOrDefault(s => s.id.Equals(songlog.Song.id)); if (song == default(Song)) { song = context.Songs.FirstOrDefault(s => s.id.Equals(songlog.Song.id)); } if (song != default(Song)) { song.modifiedDate = songlog.Song.modifiedDate; song.title = songlog.Song.title; context.Songs.Update(song); return(song); } song = new Song { createdDate = songlog.Song.createdDate, modifiedDate = songlog.Song.modifiedDate, id = songlog.Song.id, title = songlog.Song.title, ArtistId = artist.id, Artist = artist }; context.Songs.Add(song); return(song); }
public static Artist Add(SrfPlayListContext context, Songlog songlog) { var artist = context.Artists.Local.FirstOrDefault(a => a.id.Equals(songlog.Song.Artist.id)); if (artist == default(Artist)) { artist = context.Artists.FirstOrDefault(a => a.id.Equals(songlog.Song.Artist.id)); } if (artist != default(Artist)) { artist.modifiedDate = songlog.Song.Artist.modifiedDate; artist.name = songlog.Song.Artist.name; context.Artists.Update(artist); return(artist); } artist = new Artist { id = songlog.Song.Artist.id, createdDate = songlog.Song.Artist.createdDate, modifiedDate = songlog.Song.Artist.modifiedDate, name = songlog.Song.Artist.name, }; context.Artists.Add(artist); return(artist); }
public static Songlog Add(SrfPlayListContext context, Songlog songlog, Song song) { var newSonglog = new Songlog { id = songlog.id, channelId = songlog.channelId, isPlaying = songlog.isPlaying, playedDate = songlog.playedDate, Song = song }; context.Songlogs.Add(songlog); return(newSonglog); }