public ActionResult Transfer(TrensferFrom trensferFrom)
        {
            if (TransactionCustomer == null)
            {
                TempData["error"] = "Client inconnu";
                return(RedirectToAction("Index", "Home"));
            }
            var customer = customerRepo.GetCustomerByID(TransactionCustomer.ID);

            if (ModelState.IsValid)
            {
                var sourceAccount = accountRepo.GetAccountByID(trensferFrom.SourceAccount);
                ValideTrensfer(trensferFrom, customer, sourceAccount);
                if (ModelState.IsValid)
                {
                    var accounts             = accountRepo.GetAccounts();
                    var destinationAccount   = accounts.FirstOrDefault(account => account.IBAN == trensferFrom.IBAN);
                    var sourceAtaTransaction = new AccountToAcountTransaction
                    {
                        Account         = sourceAccount,
                        Source          = sourceAccount,
                        Destination     = destinationAccount,
                        Date            = DateTime.Now,
                        Amount          = trensferFrom.Amount,
                        TransactionType = TransactionType.DEBIT,
                        Title           = trensferFrom.Label + " - " + trensferFrom.DestinationFullName
                    };
                    transactionRepo.InsertTransaction(sourceAtaTransaction);
                    sourceAccount.Debit(trensferFrom.Amount);
                    if (destinationAccount != null)
                    {
                        var destinationAtaTransaction = new AccountToAcountTransaction
                        {
                            Account         = destinationAccount,
                            Date            = DateTime.Now,
                            Amount          = trensferFrom.Amount,
                            TransactionType = TransactionType.CREDIT,
                            Title           = trensferFrom.Label + " - " + trensferFrom.DestinationFullName
                        };
                        transactionRepo.InsertTransaction(destinationAtaTransaction);
                        destinationAccount.Credit(trensferFrom.Amount);
                    }
                    TempData["notice"] = "virement enregistré";
                    accountRepo.Save();
                    return(RedirectToAction("Index", "Customer"));
                }
            }
            return(View(getSelectableAccounts(customer)));
        }
        public ActionResult PrintRIBByAccount(int?id)
        {
            if (id == null || RIBCustomer == null)
            {
                return(Json(new { error = true, message = "Compte inconnu" }));
            }
            var account = accountRepo.GetAccountByID((int)id);

            if (account == null)
            {
                return(Json(new { error = true, message = "Compte inconnu" }));
            }
            if (account.Owner_ID != RIBCustomer.ID)
            {
                return(Json(new { error = true, message = "Vous n'êtes pas le propietaire de ce compte" }));
            }
            return(Json(new
            {
                RIBCustomer.FirstName,
                RIBCustomer.LastName,
                RIBCustomer.AccountNumber,
                account.BIC,
                account.IBAN
            }));
        }
 /// <summary>
 /// Finds an account searching by ID
 /// </summary>
 /// <param name="id">The ID to search by</param>
 /// <returns>An account with id</returns>
 public Account FindById(Guid id)
 {
     return(accountRepo.GetAccountByID(id));
 }
        public ActionResult InsertTestTransaction()
        {
            if (transactionRepo.GetTransactions().ToList().Count > 0)
            {
                throw new Exception("table transacion non vide");
            }
            transactionRepo.InsertTransaction(new AccountToAcountTransaction()
            {
                Account         = accountRepo.GetAccountByID(9),
                Amount          = 5000,
                Date            = DateTime.Now,
                TransactionType = TransactionType.CREDIT,
                Title           = "virement - hacene kedjar"
            });

            transactionRepo.InsertTransaction(new AccountToAcountTransaction()
            {
                Account         = accountRepo.GetAccountByID(9),
                Title           = "virement",
                Amount          = 1260,
                Date            = DateTime.Now,
                TransactionType = TransactionType.DEBIT
            });

            transactionRepo.InsertTransaction(new AgencyTransaction
            {
                Account         = accountRepo.GetAccountByID(9),
                Agency          = "LCL Paris 5",
                Amount          = 5000,
                Date            = DateTime.Now,
                TransactionType = TransactionType.CREDIT
            });
            transactionRepo.InsertTransaction(new AgencyTransaction
            {
                Account         = accountRepo.GetAccountByID(9),
                Agency          = "LCL Paris 6",
                Amount          = 500,
                Date            = DateTime.Now,
                TransactionType = TransactionType.DEBIT
            });

            transactionRepo.InsertTransaction(new AgencyTransaction
            {
                Account         = accountRepo.GetAccountByID(9),
                Agency          = "LCL Paris 7",
                Amount          = 5000,
                Date            = DateTime.Now,
                TransactionType = TransactionType.CREDIT
            });

            transactionRepo.InsertTransaction(new CDTransaction()
            {
                Account           = accountRepo.GetAccountByID(9),
                Amount            = 520,
                Date              = DateTime.Now,
                TransactionType   = TransactionType.DEBIT,
                AgencyName        = "LCL",
                CashDispanserName = "CDT-1",
                CdType            = CDType.INSIDE
            });

            transactionRepo.InsertTransaction(new CDTransaction()
            {
                Account           = accountRepo.GetAccountByID(9),
                Amount            = 560,
                Date              = DateTime.Now,
                TransactionType   = TransactionType.DEBIT,
                AgencyName        = "BNP",
                CashDispanserName = "CDT-BNP-1",
                CdType            = CDType.OUTSIDE
            });

            transactionRepo.Save();
            return(RedirectToAction("Transactions", "Transaction"));
        }