public IActionResult ApplyAsset(PurchaseWalletAssetModel assetModel) { try { var asset = _walletService.PurchaseWalletAsset(assetModel); return(Ok(asset?.Id)); } catch (Exception ex) { _logger.LogError(ex, "ERROR Publishing purchase asset: from {AppName}", Program.AppName); return(BadRequest(ex)); } }
public WalletAssetModel PurchaseWalletAsset(PurchaseWalletAssetModel walletAssetModel) { var wallet = _walletRepository.GetById(walletAssetModel.WalletId); var assetForecast = _assetService.GetAssetForecastById(walletAssetModel.AssetForecastId); if (assetForecast == null) { var asset = _assetService.GetBySymbol("BTC"); var bitcoin = _assetService.GetBitcoinAsync(walletAssetModel.Value).Result; assetForecast = new AssetForecast(asset.Id, bitcoin.Price); } var walleAsset = new WalletAsset(walletAssetModel.WalletId, assetForecast.AssetId, walletAssetModel.Value, assetForecast.Price); wallet.WalletAssets.Add(walleAsset); _walletRepository.Save(wallet); return(walleAsset.ConvertToWalletAssetModel()); }
public static WalletAsset ConvertToWalletAssetEntity(this PurchaseWalletAssetModel walletAssetModel, Guid assetId, decimal AssetPrice) => new WalletAsset(walletAssetModel.WalletId, assetId, walletAssetModel.Value, AssetPrice);