public SongContract CreateSong(CreateSongContract contract) { return(HandleTransaction(session => { if (!string.IsNullOrEmpty(contract.BasicData.NicoId)) { var existing = session.Linq <Song>().FirstOrDefault(s => s.NicoId == contract.BasicData.NicoId); if (existing != null) { throw new ServiceException("Song with NicoId '" + contract.BasicData.NicoId + "' has already been added"); } } var song = new Song(new LocalizedString(contract.BasicData.Name), contract.BasicData.NicoId); if (contract.AlbumId != null) { song.AddAlbum(session.Load <Album>(contract.AlbumId.Value), 0); } if (contract.PerformerId != null) { song.AddArtist(session.Load <Artist>(contract.PerformerId.Value)); } if (contract.ProducerId != null) { song.AddArtist(session.Load <Artist>(contract.ProducerId.Value)); } song.UpdateArtistString(); session.Save(song); return new SongContract(song); })); }