public void Init() { _server = MongoServer.Create(); var database = _server["kapital-tests"]; var collection = database.GetCollection<Transaction>("transactions"); _repository = new TransactionRepository(collection); _transactions = _repository.GetAll(); _toAdd = CreateNewTransaction("Add:TransactionRepository_BasicCrud_Tests"); _repository.Add(_toAdd); _findBy = _repository.FindBy(t => t.AccountId == _accountId).ToList(); _toDelete = CreateNewTransaction("Delete:TransactionRepository_BasicCrud_Tests"); _repository.Add(_toDelete); _repository.Delete(_toDelete.Id); _toDeletePost = _repository.FindBy(t => t.Id == _toDelete.Id).SingleOrDefault(); _toEdit = CreateNewTransaction("Edit:TransactionRepository_BasicCrud_Tests"); _repository.Add(_toEdit); _toEdit.Description = "Editted:TransactionRepository_BasicCrud_Tests"; _repository.Edit(_toEdit); _toEditPost = _repository.FindBy(t => t.Id == _toEdit.Id).SingleOrDefault(); }
public void All_MultipleTransactionsInRepo_ReturnsTransactionsInInsertionOrder() { var transactionRepository = new TransactionRepository(); transactionRepository.Add(new Transaction("01/01/2018", 100)); transactionRepository.Add(new Transaction("02/01/2018", -50)); var transactions = transactionRepository.All(); Assert.That(transactions, Is.EqualTo(new List <Transaction> { new Transaction("01/01/2018", 100), new Transaction("02/01/2018", -50) })); }
public Transaction CreateTransaction(Transaction transaction) { if (transaction is JournalTransaction journalTransaction) { var accountId = journalTransaction.Credits.FirstOrDefault()?.AccountId; journalTransaction.Amount = journalTransaction.Credits.Sum(c => c.Amount); } else { var account = this.accountRepository.FindById(transaction.AccountId.ToString()); if (account == null) { var message = $"Account with id {transaction.AccountId.ToString()} not found"; logger.LogWarning(message); throw new ResourceNotFoundException(message); } transaction.OrganizationId = account.OrganizationId; } if (!transaction.TransactionDate.HasValue) { this.logger.LogInformation("No transaction date has been mentioned. Assigning Current date."); transaction.TransactionDate = DateTime.Now; } return(repository.Add(transaction)); }
public ActionResult Create([Bind(Include = "BankAccount_From,BankAccount_To,Amount")] Transaction transaction) { transaction.ExchangeRate_ID = ExchangeRateRepository.FindLast().ID; if (ModelState.IsValid) { BankAccount bankAccount = new BankAccount(); BankAccount bankAccount_To = new BankAccount(); bankAccount = BankAccountRepository.Find(transaction.BankAccount_From); bankAccount_To = BankAccountRepository.Find(transaction.BankAccount_To); if (bankAccount != null && bankAccount_To != null && bankAccount.MoneyAmount >= transaction.Amount) { TransactionRepository.Add(transaction); bankAccount.MoneyAmount = bankAccount.MoneyAmount - transaction.Amount; BankAccountRepository.Update(bankAccount); bankAccount_To.MoneyAmount = bankAccount_To.MoneyAmount + transaction.Amount; BankAccountRepository.Update(bankAccount_To); return(RedirectToAction("Index")); } ViewBag.BankAccount_From = new SelectList(BankAccountRepository.GetList(User.Identity.GetUser_ID()), "IBAN", "IBAN", transaction.BankAccount_From); ViewBag.BankAccount_To = new SelectList(BankAccountRepository.GetList(User.Identity.GetUser_ID(), true), "IBAN", "IBAN", transaction.BankAccount_To); ViewBag.ExchangeRate_ID = new SelectList(ExchangeRateRepository.GetList(), "ID", "ID", transaction.ExchangeRate_ID); return(View(transaction)); } ViewBag.BankAccount_From = new SelectList(BankAccountRepository.GetList(User.Identity.GetUser_ID()), "IBAN", "IBAN", transaction.BankAccount_From); ViewBag.BankAccount_To = new SelectList(BankAccountRepository.GetList(User.Identity.GetUser_ID(), true), "IBAN", "IBAN", transaction.BankAccount_To); ViewBag.ExchangeRate_ID = new SelectList(ExchangeRateRepository.GetList(), "ID", "ID", transaction.ExchangeRate_ID); return(View(transaction)); }
public void Transaction_Add() { // Arrange _dbContext.Customers.Add(new Customer { Name = Guid.NewGuid().ToString(), Surname = Guid.NewGuid().ToString(), DateCreated = DateTime.UtcNow }); _dbContext.SaveChanges(); _dbContext.BankAccounts.Add(new BankAccount { DateCreated = DateTime.UtcNow, CustomerId = 1 }); _dbContext.SaveChanges(); var transactionRepository = new TransactionRepository(_dbContext); transactionRepository.Add(new Transaction { Amount = 10, BankAccountId = 1, DateCreated = DateTime.UtcNow }).GetAwaiter().GetResult(); _dbContext.SaveChanges(); // Act var transaction = _dbContext.Transactions.FirstOrDefault(); // Assert Assert.NotNull(transaction); Assert.Equal(10, transaction.Amount); }
public void CreateTransaction() { var userRepo = new UserRepository(); var accountRepo = new AccountRepository(); var transactionRepo = new TransactionRepository(); var user = TestEntityMaker.GetUser(); var account = TestEntityMaker.GetAccount(); userRepo.Add(user); accountRepo.Add(account); var transaction = new Business.Entities.Transaction(); transaction.TransactionDate = DateTime.Now; transaction.Payee = "The Man"; transaction.AccountId = account.Id; transactionRepo.Add(transaction); using (var context = new MacroMoneyContext()) { var result = context.Account .Include(i => i.Transactions) .Where(e => e.Id == account.Id); Assert.IsTrue(result.Any()); } }
private async void RegisterNewDebit() { using (var transactionRepository = new TransactionRepository()) { Transaction transaction = new Transaction(); transaction.ExpenseControlId = _expenseControl.ExpenseControlId; transaction.Day = DateTime.Now.Day; transaction.Month = DateTime.Now.Month; transaction.Year = DateTime.Now.Year; transaction.Hour = DateTime.Now.Hour; transaction.Minutes = DateTime.Now.Minute; transaction.Seconds = DateTime.Now.Second; transaction.TransactionType = Enums.TransactionType.Debit; transaction.CategoryId = SelectedCategory.CategoryId; transaction.Value = Value; transaction.Description = Description; try { transactionRepository.Add(transaction); var parameter = new NavigationParameters(); parameter.Add("expenseControlId", _expenseControl.ExpenseControlId); parameter.Add("message", "Registro de debito realizado com sucesso!"); await GoBack(parameter); } catch { Toast("Ocorreu uma falha ao cadastrar novo débito."); } } }
public ActionResult UploadImage(Image image) { if (HttpContext.Request.Files[0].ContentLength == 0) { ModelState.AddModelError("image", "Image is null , Please set Image"); return(View()); } image.image = HttpContext.Request.Files[0]; if (image.image != null) { // Validate the uploaded image(optional) var imageId = transactionRepository.nextid().FirstOrDefault().ToString(); var imagepath = ConfigurationManager.AppSettings["FileImagePath"]; var imageName = imageId + '_' + Session["ID"].ToString() + '_' + image.image.FileName.ToString(); // Get the complete file path var fileSavePath = Path.Combine(imagepath + imageName); // Save the uploaded file to "UploadedFiles" folder image.image.SaveAs(fileSavePath); image.hash = imageupload.ConvertSavedFileToSha(fileSavePath); var transaction = new Transaction() { id = Int32.Parse(imageId), member_id = Int32.Parse(Session["ID"].ToString()), filename = imageName, filepath = imagepath, date = DateTime.Now.ToString() }; transactionRepository.Add(transaction); HttpContext.Response.Clear(); //Declare needed resources string script = "<script src='/node_modules/web3/dist/web3.min.js'></script><script src='/Scripts/WebMainConfig.js'></script>" + //Declare the Account "<script>web3.eth.defaultAccount = web3.eth.accounts[0];" + //Declare the Contract Abi "var ContractAbi = web3.eth.contract([{'constant':false,'inputs':[{'name':'_id','type':'uint256'},{'name':'_fileid','type':'uint256'},{'name':'_fileHash','type':'string'},{'name':'_date','type':'string'}],'name':'AddFiles','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'anonymous':false,'inputs':[{'indexed':false,'name':'id','type':'uint256'},{'indexed':false,'name':'fileid','type':'uint256'},{'indexed':false,'name':'fileHash','type':'string'},{'indexed':false,'name':'date','type':'string'}],'name':'FileUploadEvent','type':'event'}]);" + //Declare the contract Address "var ImageContract = ContractAbi.at('0x538882ec49974f8815fee55ad7b40d6dd4b6b75d'); var fileid = web3.eth.blockNumber + 1;" + //Declare the transaction "ImageContract.AddFiles(" + Session["ID"] + "," + imageId + ",'" + image.hash + "','" + DateTime.Now + "', { gas: 999999 });" + "window.location.href = '/Transaction/Transactionlist'; </script>"; return(Content(script)); } return(View()); }
private async void btnSave_Click_1(object sender, EventArgs e) { try { if (txtExtra.Text.Trim() == string.Empty || txtAmount.Text.Trim() == string.Empty) { MessageBox.Show("All fields required....", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtAmount.Focus(); return; } Transaction transaction = new Transaction() { Amount = (decimal)Convert.ToDouble(txtAmount.Text), Extras = (double)Convert.ToDouble(txtExtra.Text), PaymentMethod = GetSelectedPaymentMethod(), Date = DateTime.Now }; await _transactionRepository.Add(transaction); OnLoadData(); this.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Add(BudgetTransaction transaction) { var tranRepo = new TransactionRepository(_db); transaction.PrepareToCrate(); tranRepo.Add(transaction); tranRepo.Save(); }
public void RepositoriesFullInsert() { DigitalSignatureUtils.AssignKeyPair("addr3"); TransactionPoolRepository tpr = new TransactionPoolRepository(); TransactionPool tp = new TransactionPool { Timestamp = DateTime.Now }; int poolId = tpr.Add(tp); Assert.AreEqual(poolId, tpr.Get(poolId).Id); TransactionRepository tr = new TransactionRepository(); Transaction t = new Transaction { PoolId = poolId, SenderId = 6, RecipientId = 1, Amount = 10, Status = TransactionStatus.confirmed.ToString(), Timestamp = DateTime.Now }; int transactionId = tr.Add(t); Assert.AreEqual(transactionId, tr.Get(transactionId).Id); BlockRepository br = new BlockRepository(); Block b = new Block { PoolId = poolId, PreviousHash = br.Get().Last().Hash, Timestamp = DateTime.Now }; b.AssignPool(); b.ComputeHash(); b.Signature = Convert.ToBase64String( DigitalSignatureUtils.SignData( Convert.FromBase64String( b.Hash ) ) ); int blockId = br.Add(b); Assert.AreEqual(blockId, br.Get(blockId).Id); }
public void StoreATransaction() { var transaction = GetTransaction(new Money(1000m), _Today); _TransactionRepository.Add(transaction); Assert.AreEqual(1, _TransactionRepository.AllTransactions().Count); Assert.AreEqual(GetTransaction(new Money(1000m), _Today), _TransactionRepository.AllTransactions()[0]); }
public void Add(Transaction model) { var transaction = MapToTable(model); if (transaction.Tag == null) { transaction.Tag = string.Empty; } transactionRepository.Add(transaction); }
private void SaveTransaction(TransactionMessage txnMessage) { _accountBalance.Update(txnMessage.Amount); _repository.Add(new Transaction { AccountNumber = txnMessage.Account, Amount = txnMessage.Amount, StartDate = txnMessage.StartDate }); }
public void Add_EmptyTransactionRepo_AddsTransactionToRepo() { var transactionRepository = new TransactionRepository(); transactionRepository.Add(new Transaction("01/02/2018", 100)); Assert.That(transactionRepository.All(), Is.EqualTo(new List <Transaction> { new Transaction("01/02/2018", 100) })); }
public int AddTransaction(TransactionDTO data) { try { var A = new TransactionRepository(); return(A.Add(data)); } catch (Exception e) { throw new FaultException <Exception>(e); } }
public override Result Execute() { To.Amount += _transaction.Amount; _transaction.Result = new Result(true, "Crediting Successful!"); using (var repo = new WalletRepository()) repo.Update(To); using (var repo = new TransactionRepository()) repo.Add(_transaction); return(_transaction.Result); }
public void Transactions_Repository_Add_ShouldBeOk() { //Action var orderRegistered = _repository.Add(_transaction); //Verify orderRegistered.Should().NotBeNull(); orderRegistered.Id.Should().NotBe(0); var expectedCustomer = _ctx.Transactions.Find(orderRegistered.Id); expectedCustomer.Should().NotBeNull(); expectedCustomer.Should().Be(orderRegistered); }
public TransactionDTO Buy(string ticker, int quantity, string username) { var stock = _stockRepo.FindStock(ticker).FirstOrDefault(); var user = _userRepo.FindByName(username); var transaction = new Transaction() { Stock = stock, User = user, Price = stock.Price, Quantity = quantity, Type = "buy" }; _transactionRepo.Add(transaction); _transactionRepo.SaveChanges(); return(new TransactionDTO() { Ticker = transaction.Stock.Ticker, Price = transaction.Price, Quantity = transaction.Quantity, DateCreated = transaction.DateCreated }); }
public Block GenerateBlock(int senderId, int recipientId, float amount) { TransactionPoolRepository tpr = new TransactionPoolRepository(); TransactionPool tp = new TransactionPool { Timestamp = DateTime.Now }; int poolId = tpr.Add(tp); TransactionRepository tr = new TransactionRepository(); Transaction t = new Transaction { PoolId = poolId, SenderId = senderId, RecipientId = recipientId, Amount = amount, Status = TransactionStatus.confirmed.ToString(), Timestamp = DateTime.Now }; int transactionId = tr.Add(t); Block b = new Block { PoolId = poolId, PreviousHash = Blocks.Last().Hash, Timestamp = DateTime.Now }; b.AssignPool(); b.ComputeHash(); b.Signature = Convert.ToBase64String( DigitalSignatureUtils.SignData( Convert.FromBase64String( b.Hash ) ) ); return(b); }
public IHttpActionResult AddTransaction([FromBody] Transaction transaction) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _transrepository.Add(transaction); } catch (Exception ex) { throw ex; } int res = _transrepository.UpdateBalance(transaction); return(Ok(res)); }
/// <summary> /// Adiciona transação e caulcula MDR /// </summary> /// <returns>The add.</returns> /// <param name="transactionRequest">Transaction request.</param> public TransactionResponse Add(TransactionRequest transactionRequest) { var acquirer = GetAcquirer(transactionRequest.Adquirente); var transaction = new Transaction { TransactionType = GetTransactionType(transactionRequest.Tipo), AcquirerId = acquirer.Id, BrandId = GetBrand(acquirer, transactionRequest.Bandeira).Id, Value = transactionRequest.Valor }; transactionRepository.Add(transaction); var netMdr = merchantDiscountRateService.CalculateMerchantDiscountRate(transaction); var response = new TransactionResponse(netMdr); return(response); }
public void Can_add_new_transaction() { DateTime testDate = new DateTime(2009, 1, 28); Transaction transaction = new Transaction { Date = testDate, Description = "Test Transaction2", IsVerified = true }; ITransactionRepository repository = new TransactionRepository(); repository.Add(transaction); using (ISession session = SessionFactory.OpenSession()) { var fromDb = session.Get<Transaction>(transaction.Id); Assert.IsNotNull(fromDb); Assert.AreNotSame(transaction, fromDb); Assert.AreEqual(transaction.Date, fromDb.Date); Assert.AreEqual(transaction.IsVerified, fromDb.IsVerified); Assert.AreEqual(transaction.Description, fromDb.Description); Assert.AreEqual(transaction.BusinessKey, fromDb.BusinessKey); } }
public override Result Execute() { if (From.Amount - _transaction.Amount < From.MinAmount) { _transaction.Result = new Result(false, "Not Enough Amount!"); } else { From.Amount -= _transaction.Amount; _transaction.Result = new Result(true, "Withdrawal Successful!"); } using (var repo = new WalletRepository()) repo.Update(From); using (var repo = new TransactionRepository()) repo.Add(_transaction); return(_transaction.Result); }
public static void ImportFromExcelFile(string filename) { IDictionary<string, AccountType> accountTypes = new Dictionary<string, AccountType>(); IDictionary<string, AccountCategory> accountCategories = new Dictionary<string, AccountCategory>(); IDictionary<string, Account> accounts = new Dictionary<string, Account>(); Iesi.Collections.Generic.ISet<Item> items = new HashedSet<Item>(); IDictionary<int, Transaction> transactions = new Dictionary<int, Transaction>(); OleDbConnection excelConnection; excelConnection = new OleDbConnection( "Provider=Microsoft.ACE.OLEDB.12.0; " + "Data Source=" + filename + "; " + "Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\""); excelConnection.Open(); RecreateDatabase(); ImportAccountTypes(excelConnection, accountTypes); ImportAccountCategories(excelConnection, accountCategories); ImportAccounts(excelConnection, accounts, accountTypes, accountCategories); ImportTransactions(excelConnection, transactions); ImportItems(excelConnection, items, accounts, transactions); AccountTypeRepository atr = new AccountTypeRepository(); AccountCategoryRepository acr = new AccountCategoryRepository(); AccountRepository ar = new AccountRepository(); TransactionRepository tr = new TransactionRepository(); ItemRepository ir = new ItemRepository(); foreach (AccountType at in accountTypes.Values) atr.Add(at); foreach (AccountCategory ac in accountCategories.Values) acr.Add(ac); foreach (Account a in accounts.Values) ar.Add(a); foreach (Transaction t in transactions.Values) tr.Add(t); foreach (Item i in items) ir.Add(i); excelConnection.Close(); }
public void AddTransaction(params Transaction[] transactions) { _transactionRepository.Add(transactions); }
public Response Post([FromBody] Transaction value) { return(repo.Add(value)); }
public void AddTransaction(Transaction transaction) { _transactionRepository.Add(transaction); }
public void Can_get_next_Transaction_Business_Key() { ITransactionRepository repository = new TransactionRepository(); var fromDb = repository.GetNextTransactionBusinessKey(); DateTime testDate = new DateTime(2009, 1, 28); Transaction _transaction4 = new Transaction { Date = testDate.AddDays(1), BusinessKey = repository.GetNextTransactionBusinessKey(), Description = "Test Transaction4", IsVerified = true }; repository.Add(_transaction4); var fromDb2 = repository.GetNextTransactionBusinessKey(); Assert.IsNotNull(fromDb); Assert.IsNotNull(fromDb2); Assert.AreNotEqual(fromDb, fromDb2); Assert.AreEqual(4, fromDb); Assert.AreEqual(5, fromDb2); }