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))); }
// GET: CustomersGenerated/Delete/5 public ActionResult Delete(int?id) { if (!IsConnected) { return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Customer customer = customerRepo.GetCustomerByID((int)id); if (customer == null) { return(HttpNotFound()); } return(View(customer)); }