public ActionResult GetAllMusics() { try { var music = _musicRepository.Get(); return(Ok(music)); } catch (Exception ex) { return(StatusCode(404, "Music not Found")); } }
async Task <Guid> IMusicAssetTransferService.Create(Guid musicId, string fromUserId, string toUserId, int buyerId, TranTypes tranType, FanTypes fanType, int duration, decimal amountValue, string key2) { var music = musicRepository.Get(musicId); DateTime startDate = DateTime.UtcNow; uint currentTime = (uint)startDate.ToUnixTimestamp(); DateTime endDate = startDate.AddDays(duration); uint endDateTimeStamp = (uint)endDate.ToUnixTimestamp(); var transfer = new MusicAssetTransfer() { MusicId = music.Id, FromId = fromUserId, ToId = toUserId, BuyerId = buyerId, Key2 = key2, DateTransferred = currentTime, TranType = tranType, FanType = fanType, DateStart = currentTime, DateEnd = endDateTimeStamp, IsPermanent = false, IsConfirmed = true, DateCreated = DateTime.UtcNow, AmountValue = amountValue }; var newTransferId = musicAssetTransferRepository.CreateAndReturnId(transfer); var deployContract = ethereumService.DeployContract(); bool isCreatedContract = false; do { var receipt = deployContract.Result; if (receipt == null) { continue; } if (receipt.Status.Value == (new HexBigInteger(1)).Value) { isCreatedContract = true; var function = ethereumService.GetFunction(EthereumFunctions.AddTransactionMusic); var transactionHash = await function.SendTransactionAsync( ethereumService.GetEthereumAccount(), new HexBigInteger(6000000), new HexBigInteger(Nethereum.Web3.Web3.Convert.ToWei(10, UnitConversion.EthUnit.Gwei)), new HexBigInteger(0), functionInput : new object[] { newTransferId.ToString(), transfer.MusicId.ToString(), transfer.FromId.ToString(), transfer.ToId.ToString(), transfer.Key2, transfer.TranType, transfer.FanType, transfer.DateStart, transfer.DateEnd, transfer.IsPermanent, transfer.IsConfirmed }); var privateKey = musicAssetTransferRepository.GetUserInfo(buyerId).OwnerPrivateKey; //var privateKey = "0xC40B82DCA66F1B0F117851AEF8E40D197F55499B09858B89AF2F8FF3B4FE83F3"; var account = new Account(privateKey); Web3 web3 = new Web3(account, "https://ropsten.infura.io/v3/aaceb4b7c236404e9eb5416bef5292e0"); var transaction = web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(transfer.ToId.ToString(), amountValue); transfer.TransactionHash = transactionHash; transfer.ContractAddress = ethereumService.GetMasterContractAddress(); musicAssetTransferRepository.Update(transfer); } }while (isCreatedContract != true); BackgroundJob.Schedule <IMusicAssetTransferUndergroundJob>( job => job.WaitForTransactionToSuccessThenFinishCreating(transfer), TimeSpan.FromSeconds(3) ); return(newTransferId); }