public async Task SaveWalletTransactionAsync(WalletTransaction walletTransaction) { var item = Mapping.Mapper.Map <WalletTransactionAdapter>(walletTransaction); WalletTransactionAdapter checkExist = _walletTransactionsAdapter.Find(x => x.Id.Equals(item.Id)).FirstOrDefault(); _walletTransactionsAdapter.Upsert(item); }
private void CheckNewTransaction(Wallet w, WalletTransaction newTx) { if (this.Txs == null) { return; } this.UpdateWalletData(); Money val = newTx.Balance; if (val < 0) { // SENT BITCOIN string amount = val.Abs().ToUnit(MoneyUnit.BTC).ToString(); } else { // RECEIVED BITCOIN string amount = val.ToUnit(MoneyUnit.BTC).ToString(); TimeSpan timespan = DateTimeOffset.UtcNow - newTx.AddedDate; const int TIMESPAN_TOLERANCE = 5; // in seconds if (timespan.Seconds <= TIMESPAN_TOLERANCE) { App.Current.Dispatcher.Invoke(() => Messenger.Default.Send <string>(amount, "NewReceivedTransactionFound")); } } this.GeneratePubKeys(); }
public void SetTransaction(string transactionId) { _transaction = _transactionsRepository.Items.Find(t => t.Id == transactionId); if (_transaction.TransferTransaction == null) { FirstItemLabelText = "Account:"; FirstItemButtonText = _transaction.Account.Name; SecondItemLabelText = "Category:"; SecondItemButtonText = _transaction.Category.Name; AmountLabelText = _transaction.Amount.ToString("0.##"); } else { FirstItemLabelText = "Source account:"; FirstItemButtonText = _transaction.TransferTransaction.SourceTransaction.Account.Name; SecondItemLabelText = "Target account:"; SecondItemButtonText = _transaction.TransferTransaction.TargetTransaction.Account.Name; AmountLabelText = _transaction.TransferTransaction.SourceTransaction.Amount.ToString("0.##"); } }
public async Task AddAsync_InsufficientFunds_ReturnsSuccessFalse() { var fakeWallet = new Wallet() { Guid = Guid.NewGuid(), Balance = 99 }; var fakeTransaction = new WalletTransaction() { Guid = Guid.NewGuid(), Amount = 100, TransactionType = TransactionType.Stake, WalletGuid = fakeWallet.Guid }; _walletServiceMock.Setup(s => s.GetByGuidAsync(fakeTransaction.WalletGuid)).ReturnsAsync(fakeWallet); _transactionRepositoryMock.Setup(r => r.GetByGuidAsync(fakeTransaction.Guid)).Returns(Task.FromResult <WalletTransaction>(null)); var result = await transactionService.AddAsync(fakeTransaction); using (new AssertionScope()) { result.Sucess.Should().BeFalse(); result.Message.Should().Be("Not enough gold."); _transactionRepositoryMock.Verify(r => r.AddAsync(It.IsAny <WalletTransaction>()), Times.Never); _walletServiceMock.Verify(s => s.UpdateAsync(It.IsAny <Wallet>()), Times.Never); } }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var user = await _userManager.FindByNameAsync(_userAccessor.GetCurrentUserName()); if (user == null) { Console.Write("User is Null"); throw new RestException(HttpStatusCode.Unauthorized); } var walletTransaction = new WalletTransaction { Id = new Guid(), Type = "Deposit", TransactionDate = DateTime.Now, Amount = request.Amount, AppUser = user }; user.CashAmount = user.CashAmount + request.Amount; _context.WalletTransactions.Add(walletTransaction); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem Adding Funds"); }
private Task CommitTransaction(UserWallet wallet, WalletTransaction transaction) { wallet.MoneyAmmount += transaction.MoneyInvolved; _unitOfWork.Add(transaction); _unitOfWork.Update(wallet); return(_unitOfWork.SaveChanges()); }
public TransactionViewModel(Wallet wallet, WalletTransaction transaction, BlockIdentity transactionLocation) { _transaction = transaction; _location = transactionLocation; var groupedOutputs = _transaction.NonChangeOutputs.Select(o => { var destination = wallet.OutputDestination(o); return(new GroupedOutput(o.Amount, destination)); }).Aggregate(new List <GroupedOutput>(), (items, next) => { var item = items.Find(a => a.Destination == next.Destination); if (item == null) { items.Add(next); } else { item.Amount += next.Amount; } return(items); }); Depth = BlockChain.Depth(wallet.ChainTip.Height, transactionLocation); Inputs = _transaction.Inputs.Select(input => new Input(-input.Amount, wallet.AccountName(input.PreviousAccount))).ToArray(); Outputs = _transaction.Outputs.Select(output => new Output(output.Amount, wallet.OutputDestination(output))).ToArray(); GroupedOutputs = groupedOutputs; }
public async Task <FundWalletResponseModel> Handle(FundWalletRequestModel request, CancellationToken cancellationToken) { if (request.Amount < 1) { throw new ArgumentException("Minimum allowed deposit amount is 1"); } var wallet = _walletRepo.SingleOrDefault(w => w.AccountNumber == request.AccountNumber); if (wallet == null) { throw new ArgumentException("Invalid wallet account number"); } var trans = new WalletTransaction { AccountNumber = request.AccountNumber, Amount = request.Amount, BalanceAfter = wallet.Balance + request.Amount, BalanceBefore = wallet.Balance, CustomerId = WebHelper.CurrentCustomerId, Description = request.Description, Id = Guid.NewGuid(), Status = EWalletTransactionStatus.APPROVED, TransReferenceId = request.TransReference, Type = EWalletTransactionType.DEPOSIT }; await _walletTransRepo.AddAsync(trans); wallet.Balance += request.Amount; _walletRepo.Update(wallet); var response = _mapper.Map <FundWalletResponseModel>(trans); response.Label = wallet.Label; return(response); }
public static Message <string, string> Create_WalletTransaction(WalletTransaction objectToSend) { if (objectToSend.BrandName == null) { throw new ArgumentException($"{nameof(objectToSend.BrandName)} cannot be null."); } Message <string, string> message = new Message <string, string> { Key = objectToSend.CustomerId.ToString(), Value = JsonConvert.SerializeObject(objectToSend, Formatting.None) }; string MESSAGE_TYPE = objectToSend.GetType().Name; string BRAND_NAME = objectToSend.BrandName.ToLower(); message.Headers = new Headers { { KafkaHeaders.Source, Encoding.UTF8.GetBytes(SOURCE) }, { KafkaHeaders.Type, Encoding.UTF8.GetBytes(MESSAGE_TYPE) }, { KafkaHeaders.BrandName, Encoding.UTF8.GetBytes(BRAND_NAME) }, }; return(message); }
private async void btnSpendCash_Click_1(object sender, RoutedEventArgs e) { // Find the payment instrument to use PaymentInstrument walletPay; walletPay = Microsoft.Phone.Wallet.Wallet.FindItem("Credit") as PaymentInstrument; if (walletPay == null) { MessageBox.Show("Wallet not found"); return; } // Create the transaction WalletTransaction transaction = new WalletTransaction(); Random rand = new Random(); transaction.DisplayAmount = rand.Next(5, 50).ToString(); transaction.Description = "Coffee Purchase"; transaction.TransactionDate = DateTime.Now; // Add the transaction to the wallet walletPay.TransactionHistory.Add("Coffee Purchase " + DateTime.Now, transaction); await walletPay.SaveAsync(); MessageBox.Show("Transaction stored"); }
public static bool RelevantTransaction(WalletTransaction tx, Account account, out Amount debit, out Amount credit) { debit = 0; credit = 0; var relevant = false; foreach (var input in tx.Inputs) { if (input.PreviousAccount == account) { relevant = true; debit -= input.Amount; } } foreach (var output in tx.Outputs) { var controlledOutput = output as WalletTransaction.Output.ControlledOutput; if (controlledOutput?.Account == account) { relevant = true; credit += output.Amount; } } return relevant; }
public ActionResult DeleteConfirmed(int id) { WalletTransaction wallettransaction = db.WalletTransactions.Find(id); db.WalletTransactions.Remove(wallettransaction); db.SaveChanges(); return(RedirectToAction("Index")); }
public TransactionModel(WalletTransaction transaction) { _Transaction = transaction; BlockInfo = _Transaction.BlockInformation; BlockId = GetBlockId(); Confirmations = GetConfs(); State = GetTxState(); Action = GetTxAction(); }
public void ConfigureFor(WalletTransaction transaction) { CategoryNameLabel.Text = transaction.Category.Name; AmountLabel.Text = CurrenciesList.GetCurrency(transaction.Account.Currency).GetFormattedValue(transaction.Amount); DateLabel.Text = transaction.Date.Date.ToString("d"); AccountNameLabel.Text = transaction.Account.Name; AmountLabel.TextColor = transaction.Amount < 0 ? UIColor.Red : _green; CategoryImageView.Image = UIImage.FromFile("shopping"); }
/// <summary> /// transaction /// </summary> /// <param name="des">description</param> /// <param name="pay">paymet</param> public async void Transaction(string des, double pay) { try { SampleItem itemData = null; bool isFind = false; foreach (GroupInfoList group in Global.Current.SampleItems.Data) { foreach (SampleItem item in group.ItemContent) { if (item.Title == des) { itemData = item; itemData.Price = "¥" + pay.ToString(); des = des + "-付款"; isFind = true; break; } } if (isFind) { break; } } if (itemData != null) { Global.Current.Serialization.SaveOrder(itemData); } WalletItem walletItem = await this.wallet.GetWalletItemAsync(conCardID); if (walletItem != null && walletItem.DisplayProperties.ContainsKey(conCardMoney)) { string money = walletItem.DisplayProperties[conCardMoney].Value; string updateMoney = (double.Parse(money) - pay).ToString(); walletItem.DisplayProperties[conCardMoney].Value = updateMoney; await this.wallet.UpdateAsync(walletItem); WalletTransaction walletTransaction = new WalletTransaction(); walletTransaction.Description = des; walletTransaction.DisplayAmount = "¥" + pay.ToString(); walletTransaction.TransactionDate = DateTime.Now; walletTransaction.IgnoreTimeOfDay = false; walletTransaction.DisplayLocation = "Bank on 5th"; // Add the transaction to the TransactionHistory of this item. walletItem.TransactionHistory.Add("transaction" + DateTime.Now.Ticks.ToString(), walletTransaction); // Update the item in Wallet. await this.wallet.UpdateAsync(walletItem); Global.Current.Notifications.CreateToastNotifier("提示", "付款成功"); Global.Current.Notifications.CreateTileWide310x150Text09("付款成功", "恭喜您付款成功"); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public ActionResult Edit([Bind(Include = "TransactionId,TransactionType,TransactionDesc,Amount,TransactionDate,TransactionTime,WalletId")] WalletTransaction walletTransaction) { if (ModelState.IsValid) { db.Entry(walletTransaction).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(walletTransaction)); }
// // GET: /WalletTransaction/Details/5 public ActionResult Details(int id = 0) { WalletTransaction wallettransaction = db.WalletTransactions.Find(id); if (wallettransaction == null) { return(HttpNotFound()); } return(View(wallettransaction)); }
public void Init() { _wtx = new WalletTransaction(); var _tx = Transaction.Parse("010000000200010000000000000000000000000000000000000000000000000000000000000000000049483045022100d180fd2eb9140aeb4210c9204d3f358766eb53842b2a9473db687fa24b12a3cc022079781799cd4f038b85135bbe49ec2b57f306b2bb17101b17f71f000fcab2b6fb01ffffffff0002000000000000000000000000000000000000000000000000000000000000000000004847304402205f7530653eea9b38699e476320ab135b74771e1c48b81a5d041e2ca84b9be7a802200ac8d1f40fb026674fe5a5edd3dea715c27baa9baca51ed45ea750ac9dc0a55e81ffffffff010100000000000000015100000000"); _wtx.Transaction = _tx; _wtx.ReceivedCoins = _tx.Outputs.AsCoins().ToArray(); _wtx.SpentCoins = new Coin[0]; _txmodel = new TransactionModel(_wtx); }
public ActionResult Create([Bind(Include = "TransactionId,TransactionType,TransactionDesc,Amount,TransactionDate,TransactionTime,WalletId")] WalletTransaction walletTransaction) { if (ModelState.IsValid) { db.WalletTransactions.Add(walletTransaction); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(walletTransaction)); }
// // GET: /WalletTransaction/Edit/5 public ActionResult Edit(int id = 0) { WalletTransaction wallettransaction = db.WalletTransactions.Find(id); if (wallettransaction == null) { return(HttpNotFound()); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", wallettransaction.CustomerID); return(View(wallettransaction)); }
public ActionResult Edit(WalletTransaction wallettransaction) { if (ModelState.IsValid) { db.Entry(wallettransaction).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", wallettransaction.CustomerID); return(View(wallettransaction)); }
public async Task SaveWalletTransactionAsync(WalletTransaction walletTransaction) { var item = _walletTransactions.Where(x => x.Id.Equals(walletTransaction.Id)).FirstOrDefault(); if (item != null) { _walletTransactions.Remove(item); } walletTransaction.Id = Guid.NewGuid(); _walletTransactions.Add(walletTransaction); }
public async void UpdateWalletState() { var walletState = WalletTransactionsController.GetWalletState(_context); var transaction = new WalletTransaction { WalletBefore = walletState, WalletAfter = walletState - NewTicketData.Wager, TransactionDate = DateTime.Now }; await new WalletTransactionsController(_context).Create(transaction); }
public async Task <IActionResult> Create([Bind("Id,WalletBefore,WalletAfter,TransactionDate")] WalletTransaction walletTransaction) { if (!ModelState.IsValid) { return(View(walletTransaction)); } _context.Add(walletTransaction); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public Response <List <WalletTransaction> > GetAccountTransactionsHistoryList(long accountNumber) { var response = new Response <List <WalletTransaction> >() { ErrorMessage = string.Empty, Data = new List <WalletTransaction>() }; try { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (var command = new SqlCommand( "SELECT TransactionDate, Id, AccountNumber, TransactionType, Credit, Debit, TransactionReference, Balance FROM [Transaction] WHERE AccountNumber = @AccountNumber", connection)) { command.Parameters.AddWithValue("@AccountNumber", accountNumber); using (var reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { var transaction = new WalletTransaction() { TransactionDate = (DateTime)reader["TransactionDate"], Id = (int)reader["Id"], AccountNumber = (long)reader["AccountNumber"], Credit = reader["Credit"] as decimal?, Debit = reader["Debit"] as decimal?, Balance = (decimal)reader["Balance"], TransactionType = (TransactionType)reader["TransactionType"], TransactionReference = reader["TransactionReference"] as int? }; response.Data.Add(transaction); } } } } } } catch (Exception) { response.ErrorMessage = "Oops. Something went wrong."; } return(response); }
public static TxAction GetTxAction(WalletTransaction tx) { Money amount = tx.Balance; if (amount < 0) { return(TxAction.Sent); } else { return(TxAction.Received); } }
public async Task <WalletTransaction> AddAsync(WalletTransaction transaction) { if (transaction is null) { throw new ArgumentNullException(nameof(transaction)); } await Context.Transactions.AddAsync(transaction); await Context.SaveChangesAsync(); return(transaction); }
public override void ApplyTransaction(Transaction tx) { lock (unconfirmed) { unconfirmed[tx.Hash] = tx; } WalletTransaction?.Invoke(this, new WalletTransactionEventArgs { Transaction = tx, RelatedAccounts = tx.Witnesses.Select(p => p.ScriptHash).Union(tx.Outputs.Select(p => p.ScriptHash)).Where(p => Contains(p)).ToArray(), Height = null, Time = DateTime.UtcNow.ToTimestamp() }); }
public async Task SaveWalletTransactionAsync(WalletTransaction walletTransaction) { var item = Mapping.Mapper.Map <WalletTransactionAdapter>(walletTransaction); WalletTransactionAdapter checkExist = await _walletTransactionsAdapter.Find(x => x.Id.Equals(item.Id)).FirstOrDefaultAsync(); if (checkExist != null) { await _walletTransactionsAdapter.ReplaceOneAsync(x => x.Id.Equals(item.Id), item); } else { await _walletTransactionsAdapter.InsertOneAsync(item); } }
// GET: WalletTransactions/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WalletTransaction walletTransaction = db.WalletTransactions.Find(id); if (walletTransaction == null) { return(HttpNotFound()); } return(View(walletTransaction)); }
public static void WalletTransactionTest() { var url = new Uri("https://api.eveonline.com/char/WalletTransactions.xml.aspx"); const int characterId = 123456; Dictionary <string, string> data = ApiTestHelpers.GetBaseTestParams(); data["accountKey"] = "1000"; data.Add(ApiConstants.CharacterId, characterId.ToString(CultureInfo.InvariantCulture)); IHttpRequestProvider mockProvider = MockRequests.GetMockedProvider(url, data, ApiTestHelpers.GetXmlData("TestData\\Api\\WalletTransactions.xml")); using ( var client = new EveAPI(ApiTestHelpers.EveServiceApiHost, ApiTestHelpers.GetNullCacheProvider(), mockProvider)) { Task <EveServiceResponse <IEnumerable <WalletTransaction> > > task = client.Character.WalletTransactionsAsync(ApiTestHelpers.KeyIdValue, ApiTestHelpers.VCodeValue, characterId, 1000); task.Wait(); ApiTestHelpers.BasicSuccessResultValidations(task); Assert.IsNotNull(task.Result); Assert.IsNotEmpty(task.Result.ResultData); List <WalletTransaction> entries = task.Result.ResultData.ToList(); Assert.AreEqual(7, entries.Count); WalletTransaction entry = entries[6]; Assert.AreEqual(new DateTimeOffset(2010, 01, 29, 15, 45, 00, TimeSpan.Zero), entry.TransactionDateTime); Assert.AreEqual(1298649939, entry.TransactionId); Assert.AreEqual(1, entry.Quantity); Assert.AreEqual("Heavy Missile Launcher II", entry.TypeName); Assert.AreEqual(2410, entry.TypeId); Assert.AreEqual(556001.01, entry.Price); Assert.AreEqual(1703231064, entry.ClientId); Assert.AreEqual("Der Suchende", entry.ClientName); Assert.AreEqual(60004369, entry.StationId); Assert.AreEqual("Ohmahailen V - Moon 7 - Corporate Police Force Assembly Plant", entry.StationName); Assert.AreEqual("buy", entry.TransactionType); Assert.AreEqual("personal", entry.TransactionFor); } }
private async Task AddTransactionAsync() { if (walletItem == null) { rootPage.NotifyUser("Item does not exist. Add item using Scenario2", NotifyType.ErrorMessage); return; } try { // Create a transaction. WalletTransaction walletTransaction = new WalletTransaction(); walletTransaction.Description = "Double tall latte"; walletTransaction.DisplayAmount = "$3.27"; // The date and time of the transaction walletTransaction.TransactionDate = DateTime.Now; // Don't display the time of the transaction, just the date. walletTransaction.IgnoreTimeOfDay = false; // A string representing where the transaction took place. walletTransaction.DisplayLocation = "Contoso on 5th"; // Add the transaction to the TransactionHistory of this item. walletItem.TransactionHistory.Add("txnid123", walletTransaction); // Update the item in Wallet. await wallet.UpdateAsync(walletItem); rootPage.NotifyUser("Transaction added.", NotifyType.StatusMessage); } catch(Exception ex) { string errorMessage = String.Format("Could not add transaction. {0}", ex.Message); rootPage.NotifyUser(errorMessage, NotifyType.ErrorMessage); } }