예제 #1
0
        public int CreateAlbum(ModifyAlbumModel model)
        {
            try
            {
                using (var context = new SparrowMusicEntities())
                {
                    var album = new SPRW_ALBUM()
                    {
                        ARTIST_ID = model.ArtistId,
                        RELEASE_DATE = model.ReleaseDate,
                        NAME = model.AlbumName,
                        DESCRP = model.Description,
                        LAST_MAINT_USER_ID = "",
                        LAST_MAINT_TIME = DateTime.Now
                    };
                    context.SPRW_ALBUM.Add(album);
                    context.SaveChanges();

                    return album.ALBUM_ID;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #2
0
        public List<AlbumModel> GetAlbums(int artistId)
        {
            try
            {
                var model = new List<AlbumModel>();
                using (var context = new SparrowMusicEntities())
                {
                    var albums = context.SPRW_ALBUM.Where(i => i.SPRW_ARTIST.ARTIST_ID == artistId).ToList();

                    foreach (var album in albums)
                    {
                        var albumModel = new AlbumModel
                        {
                            AlbumId = album.ALBUM_ID,
                            AlbumName = album.NAME,
                            Tracks = new List<TrackModel>()
                        };

                        foreach (var track in album.SPRW_TRACK)
                        {
                            var trackModel = new TrackModel
                            {
                                TrackId = track.TRACK_ID,
                                TrackName = track.NAME
                            };
                            albumModel.Tracks.Add(trackModel);
                        }
                        model.Add(albumModel);
                    }
                }

                return model;
            }
            catch (Exception e)
            {
                throw e;
            }
        }