public IActionResult DepositMoney(decimal amount, int accountId) { var deposit = _context.Accounts.Where(a => a.AccountId == accountId).SingleOrDefault(); if (amount > 0) { Transactions transactions = new Transactions { AccountId = deposit.AccountId, Date = DateTime.Now, Type = "Debit", Operation = "Withdrawal in cash", Amount = amount, Balance = deposit.Balance + amount }; deposit.Balance += amount; _context.Add(transactions); _context.SaveChanges(); return(RedirectToAction("DepositApproved")); } else { return(RedirectToAction("DepositDenied")); } }
public IActionResult CreateCustomer(CreateCustomerViewModel register) { if (ModelState.IsValid) { Customers newCustomer = new Customers() { Gender = register.Gender, Givenname = register.Givenname, Surname = register.Surname, Streetaddress = register.Streetaddress, City = register.City, Zipcode = register.Zipcode, Country = register.Country, CountryCode = register.CountryCode, Birthday = register.Birthday, NationalId = register.NationalId, Telephonecountrycode = register.Telephonecountrycode, Telephonenumber = register.Telephonenumber, Emailaddress = register.Emailaddress }; Accounts account = new Accounts() { Frequency = "Monthly", Created = DateTime.Now, Balance = 0m }; Dispositions disposition = new Dispositions() { Type = "Owner", Customer = newCustomer, Account = account }; register.Account = account; register.Disposition = disposition; _context.Add(newCustomer); _context.Add(register.Account); _context.Add(register.Disposition); _context.SaveChanges(); return(RedirectToAction("CreateCustomerSuccess")); } else { return(View(register)); } }
public int CreateNewCustomer(string gender, string givenName, string surname, string streetAddress, string city, string Zipcode, string country, string countryCode, DateTime birthDate, string telephoneCountryCode, string telephoneNumber, string emailAddress) { Customer customer = new Customer() { Gender = gender, Givenname = givenName, Surname = surname, Streetaddress = streetAddress, City = city, Zipcode = Zipcode, Country = country, CountryCode = countryCode, Birthday = birthDate.Date, Telephonecountrycode = telephoneCountryCode, Telephonenumber = telephoneNumber, Emailaddress = emailAddress }; context.Add(customer); context.SaveChanges(); dispositionCommandHandler.CreateNewDisposition(customer.CustomerId); return(customer.CustomerId); }
public IActionResult Transfer(int fromAcc, int toAcc, decimal amount) { if (ModelState.IsValid) { var model = new TransactionViewModel(); var account1 = _context.Accounts.SingleOrDefault(k => k.AccountId == fromAcc); var account2 = _context.Accounts.SingleOrDefault(k => k.AccountId == toAcc); if (amount <= account1.Balance) { var transFrom = new Transactions() { AccountId = account1.AccountId, Date = DateTime.Now, Type = "Debit", Operation = "Withdrawal in cash", Amount = amount * -1, Balance = account1.Balance - amount }; account1.Balance -= amount; var transTo = new Transactions() { AccountId = account2.AccountId, Date = DateTime.Now, Type = "Credit", Operation = "Credit in cash", Amount = amount, Balance = account1.Balance + amount }; account2.Balance += amount; _context.Add(transFrom); _context.Add(transTo); _context.SaveChanges(); return(RedirectToAction("TransferSuccess")); } } TempData["success"] = "abc"; return(View()); }
public void CreateNewDisposition(int customerId) { Disposition disposition = new Disposition() { CustomerId = customerId, AccountId = accountCommandHandler.CreateNewAccount(), Type = "OWNER" }; context.Add(disposition); context.SaveChanges(); }
public int CreateNewAccount() { Account account = new Account() { Frequency = "Monthly", Created = DateTime.Now, Balance = 0 }; context.Add(account); context.SaveChanges(); return(account.AccountId); }
public void CreateTransaction(int accountId, decimal amount, decimal balance, string operation, string type) { Transaction transaction = new Transaction() { AccountId = accountId, Date = DateTime.Now.Date, Operation = operation, Amount = amount, Balance = balance, Type = type }; context.Add(transaction); context.SaveChanges(); }
public async Task AddInterest_Tests(decimal yearlyint, int accountid) { var account = new Account() { AccountId = 1, Balance = 10000 }; var command = new AddInterestCommand() { AccountId = accountid, YearlyInterest = yearlyint, LatestInterest = DateTime.Now }; var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "AddInterest_Tests") .Options; decimal expected; using (var context = new BankAppDataContext(options)) { context.Add(new Account() { AccountId = 1, Balance = 10000 }); context.SaveChanges(); var machine = new MachineDateTime() { }; machine.Now = machine.Now.AddDays(30); var handler = new AddInterestCommandHandler(context, machine); expected = 10039.73m; await handler.Handle(command, CancellationToken.None); var newbalance = await context.Accounts.SingleOrDefaultAsync(a => a.AccountId == 1); var test = Math.Round(newbalance.Balance, 2); Assert.Equal(expected, test); } }
public T Create(T entity) { db.Add(entity); db.SaveChanges(); return(entity); }