예제 #1
0
        public static Song ToSong(AddUpdateSongModel addSongModel)
        {
            if (addSongModel == null)
            {
                return(null);
            }

            var song = new Song
            {
                Id     = addSongModel.Id,
                Title  = addSongModel.Name,
                Url    = addSongModel.Url,
                Artist = new Artist {
                    Id = addSongModel.ArtistId
                },
                SongCategory = new SongCategory {
                    Id = addSongModel.SongCategoryId
                },
                Instruments = addSongModel.InstrumentIds.Select(i => new Instrument {
                    Id = i
                }),
                Tags = addSongModel.TagIds.Select(t => new Tag {
                    Id = t
                })
            };

            return(song);
        }
예제 #2
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);
        }
예제 #3
0
 public void Put([FromUri] string id, [FromBody] AddUpdateSongModel model)
 {
     _songService.Update(id, model);
 }
예제 #4
0
 public void Post([FromBody] AddUpdateSongModel model)
 {
     _songService.Add(model);
 }