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); }
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); }
public void Put([FromUri] string id, [FromBody] AddUpdateSongModel model) { _songService.Update(id, model); }
public void Post([FromBody] AddUpdateSongModel model) { _songService.Add(model); }