public async Task InsertTransaction(TransactionBaseResponse model) { var transactionHistory = new TransactionHistory { AccountId = model.AccountNumber, Amount = model.Balance, Currency = model.Currency, IsSuccess = model.Successful, Message = model.Message }; _uow.TransactionHistoryRepo.Create(transactionHistory); await _uow.SaveAsyn(); }
private Task HandleExceptionAsync(HttpContext context, Exception exception, ITransactionService transactionService) { var response = new TransactionBaseResponse { Successful = false }; var accountNumber = 0; switch (exception) { //Custom error showing to user case CustomException e: response.Message = e.ErrorMessage; response.AccountNumber = e.AccountNumber; break; case DbUpdateConcurrencyException e: accountNumber = context.Session.GetInt32("AccountNumber") ?? 0; response.AccountNumber = accountNumber; response.Message = ErrorCode.E2.GetDisplayAttribute().Name; break; //Exception by system default: accountNumber = context.Session.GetInt32("AccountNumber") ?? 0; response.AccountNumber = accountNumber; response.Message = ErrorCode.E0.GetDisplayAttribute().Name; break; } Log.Error(exception.Message, string.Empty, accountNumber); if (exception.InnerException != null) { Log.Error(exception.InnerException.Message, string.Empty, accountNumber); } context.Response.ContentType = "application/json"; return(context.Response.WriteAsync(JsonConvert.SerializeObject(response))); }