public IHttpActionResult Withdraw(WithdrawAndDepositDto withdrawDto) { var customer = _context.Accounts.Single(x => x.AccountNumber == withdrawDto.AccountNumber); if (customer.Pin != withdrawDto.pin) { return(Ok("Incorrect Pin")); } else if (customer.Balance < withdrawDto.Amount) { return(Ok("Insufficient Balance"));; } else { customer.Balance = customer.Balance - withdrawDto.Amount; Transaction current = new Transaction(); current.AccountNumber = withdrawDto.AccountNumber; current.Amount = withdrawDto.Amount; current.Date = DateTime.Now; current.TransactionTypeId = Transaction.Withdraw; _context.Transactions.Add(current); _context.SaveChanges(); return(Ok(customer.Balance)); } }
public IHttpActionResult Deposit(WithdrawAndDepositDto depositDto) { var customer = _context.Accounts.Single(x => x.AccountNumber == depositDto.AccountNumber); if (customer.Pin != depositDto.pin) { return(Ok("Incorrect Pin")); } if (depositDto.Amount > 5000) { return(Ok("Cannot deposit more than $5000 at a time.")); } else { customer.Balance = customer.Balance + depositDto.Amount; Transaction current = new Transaction(); current.AccountNumber = depositDto.AccountNumber; current.Amount = depositDto.Amount; current.Date = DateTime.Now; current.TransactionTypeId = Transaction.Deposit; _context.Transactions.Add(current); _context.SaveChanges(); return(Ok(customer.Balance)); } }