public async Task <IActionResult> Deposit(int id, [Bind("Amount")] DepositVM depositVM) { var account = await _repo.Get(id); if (ModelState.IsValid) { try { await _repo.Deposit(account, depositVM.Amount); } catch (DbUpdateConcurrencyException) { if (!AccountExists(id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(depositVM)); }
public async Task <ActionResult> Deposit(int id, decimal amount) { _logger?.LogInformation(string.Format("Attempting to deposit into account with id: {0}", id.ToString())); try { Account acctFound = null; if (amount < 0) //make sure deposit amount is positive { _logger?.LogWarning(string.Format("PUT request failed, Amount passed is less than 0. Account with ID: {0}", id.ToString())); return(StatusCode(400)); } acctFound = await _repoAccount.GetAccountDetailsByAccountID(id); //retrieve account in order to check if it exists, and manage balance if (acctFound == null) //make sure account exist in database { _logger?.LogWarning(string.Format("PUT request failed, No Account found with ID: {0} or Account is already closed", id.ToString())); return(NotFound(id)); } //deposit into account with id if it returns false then account is closed if (!await _repoAccount.Deposit(acctFound.Id, amount)) { _logger?.LogWarning(string.Format("PUT, deposit failed, Account is already closed", id.ToString())); return(NotFound(id)); } _logger?.LogInformation("PUT Success deposited into account with ID: {0} Amount: {2}", id.ToString(), amount.ToString()); await _repoAccount.SaveChanges(); return(NoContent()); } catch (Exception e) { _logger?.LogError(e, "Unexpected Error in deposit of account with ID: {0}", id.ToString()); return(StatusCode(500)); } }