public static List <Common.Song> GetSongsFromAlbum(int albumId) { using (var entities = new AlbumsCatalogueEntities()) { return(entities.Songs.Where(x => x.AlbumId == albumId).ToList().Select(x => x.ToCommon()).ToList()); } }
public static List <Common.Song> GetAll() { using (var entities = new AlbumsCatalogueEntities()) { return(entities.Songs.ToList().Select(x => x.ToCommon()).ToList()); } }
public static List <Common.Song> GetByIds(List <int> ids) { using (var entities = new AlbumsCatalogueEntities()) { return(entities.Songs.Where(x => ids.Contains(x.Id)).ToList().Select(x => x.ToCommon()).ToList()); } }
public static Common.Album GetById(int id) { using (var entities = new AlbumsCatalogueEntities()) { return(entities.Albums .Find(id) //.FirstOrDefault(x => x.Id == id) .ToCommon()); } }
public static Common.Album Create(Common.Album album) { using (var entities = new AlbumsCatalogueEntities()) { var dbAlbum = album.ToDb(); var inserted = entities.Albums.Add(dbAlbum); entities.SaveChanges(); return(inserted.ToCommon()); } }
public static List <Common.Album> GetByIds(List <int> ids) { using (var entities = new AlbumsCatalogueEntities()) { var query = entities.Albums.Where(x => ids.Contains(x.Id)); var dbResult = query.ToList(); var enumerableOfCommon = dbResult.Select(x => x.ToCommon()); var listResult = enumerableOfCommon.ToList(); return(listResult); } }
public static Common.Song Create(Common.Song song) { using (var entities = new AlbumsCatalogueEntities()) { var songToDb = song.SongToDb(); var newSong = entities.Songs.Add(songToDb); var songToCommon = newSong.ToCommon(); entities.SaveChanges(); return(songToCommon); } }
public static Common.Album Update(Common.Album album) { using (var entities = new AlbumsCatalogueEntities()) { var existing = entities.Albums.FirstOrDefault(x => x.Id == album.Id); existing.Name = album.Name; existing.ReleaseDate = album.ReleaseDate; entities.SaveChanges(); return(existing.ToCommon()); } }
public static void Delete(int id) { using (var entities = new AlbumsCatalogueEntities()) { var entity = entities.Albums.FirstOrDefault(x => x.Id == id); if (entity != null) { entities.Albums.Remove(entity); } entities.SaveChanges(); } }
public static Common.Song Update(Common.Song song) { using (var entities = new AlbumsCatalogueEntities()) { var existing = entities.Songs.FirstOrDefault(x => x.Id == song.Id); if (existing == null) { return(null); } existing.Name = song.Name; existing.Genre = (int)song.Genre; existing.Artist = song.Artist; entities.SaveChanges(); return(existing.ToCommon()); } }