コード例 #1
0
 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());
     }
 }
コード例 #2
0
 public static List <Common.Song> GetAll()
 {
     using (var entities = new AlbumsCatalogueEntities())
     {
         return(entities.Songs.ToList().Select(x => x.ToCommon()).ToList());
     }
 }
コード例 #3
0
 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());
     }
 }
コード例 #4
0
 public static Common.Album GetById(int id)
 {
     using (var entities = new AlbumsCatalogueEntities())
     {
         return(entities.Albums
                .Find(id)
                //.FirstOrDefault(x => x.Id == id)
                .ToCommon());
     }
 }
コード例 #5
0
        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());
            }
        }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
        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());
            }
        }
コード例 #9
0
        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();
            }
        }
コード例 #10
0
        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());
            }
        }