public string RemoveSong(int songId, string groupName) { string groupId = this.context.Groups .Where(g => g.Name == groupName) .Select(g => g.Id) .FirstOrDefault(); if (string.IsNullOrEmpty(groupId)) { return(string.Empty); } GroupSong groupSong = this.context.GroupSongs.FirstOrDefault(gs => gs.GroupId == groupId && gs.SongId == songId); if (groupSong == null) { return(groupId); } this.context.GroupSongs.Remove(groupSong); this.context.SaveChanges(); return(groupId); }
public string AddSong(string selectedGroup, int songId) { Song song = this.context.Songs.Find(songId); Group group = this.context.Groups.FirstOrDefault(g => g.Name == selectedGroup); GroupSong existingGroupSong = this.context.GroupSongs.FirstOrDefault(gs => gs.GroupId == group.Id && gs.SongId == song.Id); if (existingGroupSong != null) { return(existingGroupSong.GroupId); } GroupSong groupSong = new GroupSong { CreatedOn = DateTime.UtcNow, Group = group, Song = song, }; group.Songs.Add(groupSong); this.context.SaveChanges(); return(group.Id); }