public async Task <IncomeWalletTableModel> CreateUserIncomeWalletAsync(IncomeWalletTableModel wallet) { try { var p = new DynamicParameters(); p.Add("userId", wallet.UserId); p.Add("address", wallet.Address); p.Add("addressLabel", wallet.AddressLabel); p.Add("currencyAcronim", wallet.CurrencyAcronim); p.Add("new_identity", dbType: DbType.Int32, direction: ParameterDirection.Output); await _db.QueryAsync <int>("CreateUserIncomeWallet", p, commandType : CommandType.StoredProcedure); wallet.Id = p.Get <int>("new_identity"); return(wallet); } catch (Exception ex) { return(null); } }
public async Task <ActionResult> Create(string selectCurrency) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); if (!string.IsNullOrEmpty(userId)) { // create new income blockchain address(incomeWallet) string address = _walletService.GetNewAddress(selectCurrency, userId); if (address == null) { return(RedirectToAction("Index")); } await _eventsRepository.CreateEventAsync(new EventTableModel() { UserId = userId, Type = (int)EventTypeEnum.CreateAddress, Comment = $"Create address {selectCurrency}: {address}", WhenDate = DateTime.Now, CurrencyAcronim = selectCurrency }); IncomeWalletTableModel incomeWallet = new IncomeWalletTableModel() { UserId = userId, CurrencyAcronim = selectCurrency, Address = address, AddressLabel = userId }; var wallet = await _walletsRepository.GetUserWalletAsync(userId, selectCurrency); // create new inner platform wallet if (wallet == null) { wallet = await _walletsRepository.CreateUserWalletAsync(new WalletTableModel() { UserId = userId, CurrencyAcronim = selectCurrency, Value = 0, Address = _walletService.GetNewAddress(selectCurrency, userId) }); await _eventsRepository.CreateEventAsync(new EventTableModel() { UserId = wallet.UserId, Type = (int)EventTypeEnum.CreateWallet, Comment = $"Create wallet {wallet.CurrencyAcronim}", WhenDate = DateTime.Now, CurrencyAcronim = wallet.CurrencyAcronim }); } await _walletsRepository.CreateUserIncomeWalletAsync(incomeWallet); return(RedirectToAction("Index")); } else { return(Redirect("/Identity/Account/Login")); } }