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 WalletAssetModel ConvertToWalletAssetModel(this WalletAsset walletAsset) => new WalletAssetModel(walletAsset.WalletId, walletAsset.AssetId, walletAsset.InvestimentDate, walletAsset.Value, walletAsset.Price, new AssetModel(walletAsset.AssetId, walletAsset.Asset?.Symbol, walletAsset.Asset?.Name, walletAsset.Asset?.Type));