Пример #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());
            }
        }