示例#1
0
 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));
 }
示例#2
0
        // GET: BankAccounts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BankAccount bankAccount = BankAccountRepository.Find(id.Value);

            if (bankAccount == null)
            {
                return(HttpNotFound());
            }
            return(View(bankAccount));
        }
示例#3
0
        public void Find_Should_Return_Bank_Account()
        {
            //Arrange
            var dataContextMock = new Mock <DataContext>();
            var dbSetMock       = new Mock <DbSet <BankAccount> >();

            dbSetMock.Setup(b => b.Find(It.IsAny <Guid>())).Returns(new BankAccount());
            dataContextMock.Setup(b => b.Set <BankAccount>()).Returns(dbSetMock.Object);

            //Act
            var bankAccountRepository = new BankAccountRepository(dataContextMock.Object);
            var bankAccount           = bankAccountRepository.Find(new Guid());

            //Assert
            Assert.NotNull(bankAccount);
            Assert.IsAssignableFrom <BankAccount>(bankAccount);
        }
示例#4
0
        public override LoanProposal Handle(LoanProposal request)
        {
            Console.WriteLine("\nValidating bank account balance.");

            var clientId = request;

            var repo = new BankAccountRepository();

            var bankAccount = repo.Find(x => x.ClientId == request.ClientId).FirstOrDefault();

            if (bankAccount.Balance < request.Amount * 0.5m)
            {
                throw new Exception($"The client bank account must have at least 50% of the required loan amount.");
            }

            return(base.Handle(request));
        }