コード例 #1
0
        public void SongEdit(Models.Song song)
        {
            var dbSong = SongMapper.ToDatabase(song);

            _dbContext.Song.Update(dbSong);
            _dbContext.SaveChanges();
        }
コード例 #2
0
        public void Save(Models.Song song)
        {
            var dbSong = SongMapper.ToDatabase(song);

            _dbContext.Song.Add(dbSong);
            _dbContext.SaveChanges();
        }
コード例 #3
0
        public List <Models.Song> GetSongs(int id)
        {
            List <Models.Song> songs = new List <Models.Song>();
            var couples = _dbContext.ListSong.Where(x => x.PlaylistId == id);

            foreach (ListSong ls in couples)
            {
                var song = _dbContext.Song.Where(x => x.Id == ls.SongId).FirstOrDefault();
                songs.Add(SongMapper.FromDatabase(song));
            }

            return(songs);
        }
コード例 #4
0
        public SongModel GetById(string id)
        {
            var song = _songRepository.GetById(id);

            if (song == null)
            {
                throw new NotFoundException(Messages.InvalidSongId);
            }

            var songModel = SongMapper.ToSongModel(song);

            return(songModel);
        }
コード例 #5
0
        public void Add(AddUpdateSongModel addSongModel)
        {
            if (string.IsNullOrEmpty(addSongModel.Name))
            {
                throw new ValidationException(Messages.SongNameRequired);
            }

            if (string.IsNullOrEmpty(addSongModel.Url))
            {
                throw new ValidationException(Messages.SongUrlRequired);
            }

            if (string.IsNullOrEmpty(addSongModel.SongCategoryId))
            {
                throw new ValidationException(Messages.SongCategoryIdRequired);
            }

            if (string.IsNullOrEmpty(addSongModel.ArtistId))
            {
                throw new ValidationException(Messages.SongArtistIdRequired);
            }

            var songCategory = _songCategoryRepository.GetById(addSongModel.SongCategoryId);

            if (songCategory == null)
            {
                throw new NotFoundException(Messages.InvalidSongCategoryId);
            }

            var artist = _artistRepository.GetById(addSongModel.ArtistId);

            if (artist == null)
            {
                throw new NotFoundException(Messages.InvalidArtistId);
            }

            var song = SongMapper.ToSong(addSongModel);

            song.Id = SecurityUtils.GenerateEntityId();
            _songRepository.Add(song);
        }
コード例 #6
0
        public async Task <Models.Song> GetAsync(int id)
        {
            var result = await _dbContext.Song.SingleOrDefaultAsync(x => x.Id == id);

            return(SongMapper.FromDatabase(result));
        }
コード例 #7
0
 public IEnumerable <Models.Song> GetAll()
 {
     return(_dbContext.Song.Select(x => SongMapper.FromDatabase(x)));
 }
 public OperationMaster()
 {
     mapper  = new GenreMapper();
     songmmp = new SongMapper();
     dao     = SqlDao.GetInstance();
 }