public ResultDto Perform(string accountFrom, string accountTo, decimal amount) { try { var bankingApplicationService = new BankingApplicationService(); ValidatePerform(accountFrom, accountTo, amount); bankingApplicationService.PerformTransfer(new BankAccountDto { Number = accountFrom }, new BankAccountDto { Number = accountTo }, amount); return(new ResultDto { Status = "OK", Message = string.Empty }); } catch (Exception exception) { return(new ResultDto { Status = "ERROR", Message = exception.Message }); } }
public BankAccountDto Get(string id) { const string error = "No found"; try { var bankingApplicationService = new BankingApplicationService(); var account = bankingApplicationService.FindByNumber(id); if (account == null) { throw new ArgumentNullException(error); } return(new BankAccountDto { Balance = account.Balance, Id = account.Id, IsLocked = account.IsLocked, Number = account.Number }); } catch (Exception) { return(new BankAccountDto()); } }
public CustomerDto GetByCustomerId(int id) { var bankingApplicationService = new BankingApplicationService(); var byCustomerId = bankingApplicationService.GetByCustomerId(id); return(new CustomerDto { FirstName = byCustomerId.FirstName, LastName = byCustomerId.LastName }); }
public ActionResult Index() { var dataBaseService = new DataBaseService(); dataBaseService.CreateBanking(Funciones.GetConnectionString()); BankingApplicationService bankingApplicationService = new BankingApplicationService(); ViewBag.TotalCustomers = bankingApplicationService.GetAll().Count(); return(View()); }
private void ValidatePerform(string accountFrom, string accountTo, decimal amount) { var bankingApplicationService = new BankingApplicationService(); if (!bankingApplicationService.AccountEnabled(accountFrom)) { throw new Exception("La Cuenta de Origen no es valida."); } if (!bankingApplicationService.AccountEnabled(accountTo)) { throw new Exception("La Cuenta de Destino no es valida."); } var id = User.Identity.GetUserName(); if (!bankingApplicationService.OwnAccount(id, accountTo)) { throw new Exception("La Cuenta de Origen no te pertenece."); } if (accountFrom.Equals(accountTo)) { throw new Exception("No se puede transferir a la misma cuenta."); } if (amount == 0) { throw new Exception("No se puede transferir este monto."); } if (amount < 0) { throw new Exception("No se puede transferir montos negativos."); } if (bankingApplicationService.InsufficientBalance(accountFrom, amount)) { throw new Exception("Saldo Insuficiente."); } }
public TransferController() { this.bankingApplicationService = new BankingApplicationService(new BankAccountAdoNetRepository()); }