public async Task <IActionResult> Credit(TransactionEntity obj) { if (obj.Account <= 0) { return(BadRequest(new ErrorViewModel { Error = "Account number must be greater than 0" })); } if (obj.IsDebit) { return(BadRequest(new ErrorViewModel { Error = "Operation must be Credit" })); } if (obj.Value <= 0) { return(BadRequest(new ErrorViewModel { Error = "Cannot credit account with value less than 0 or 0" })); } await _transactionsRepository.InsertAsync(obj); return(Ok(new SuccessViewModel { Message = "Successfully inserted credits", Value = obj.Value, Balance = await _transactionsRepository.BalanceAsync(obj.Account) })); }
public async Task <IActionResult> Credit(TransactionEntity obj) { try { if (!ModelState.IsValid) { return(View(obj)); } if (obj.Account <= 0) { throw new TransactionException("Account number must be greater than 0"); } if (obj.IsDebit) { throw new TransactionException("Operation must be Credit"); } if (obj.Value <= 0) { throw new TransactionException("Cannot credit account with value less than 0 or 0"); } await _transactionsRepository.InsertAsync(obj); return(RedirectToAction(nameof(Success), new { Message = "Successfully inserted credits", obj.Value, Balance = await _transactionsRepository.BalanceAsync(obj.Account) })); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), new { e.Message })); } }