public IActionResult NewPayment([FromForm] NewPaymentViewModel paymentData) { NewPaymentViewModel viewModelResult = new NewPaymentViewModel() { PaymentStatus = NewPaymentStatus.Failed }; if (!ModelState.IsValid || paymentData == null || paymentData.SourceAccount == null || paymentData.Amount == null ) { return(PartialView("_NewPaymentPartial", viewModelResult)); } ModelState.Clear(); try { var userId = userManager.GetUserId(User); paymentsService.CreateAccountPayment(userId, paymentData.SourceAccount.Value, paymentData.Amount.Value, paymentData.DestinationName, paymentData.DestinationIBAN, paymentData.Details); viewModelResult.PaymentMessage = "Done"; viewModelResult.PaymentStatus = NewPaymentStatus.Created; } catch (NotEnoughFundsException) { viewModelResult.PaymentStatus = NewPaymentStatus.Failed; viewModelResult.PaymentMessage = "Not enough funds available"; } catch (WrongCurrencyException) { viewModelResult.PaymentStatus = NewPaymentStatus.Failed; viewModelResult.PaymentMessage = "Payments not allowed for accounts with different currency"; } catch (Exception e) { viewModelResult.PaymentStatus = NewPaymentStatus.Failed; viewModelResult.PaymentMessage = "Unexpected error occured"; } return(PartialView("_NewPaymentPartial", viewModelResult)); }
public IActionResult New([FromForm] NewPaymentViewModel paymentData) { NewPaymentViewModel viewModelResult = new NewPaymentViewModel() { PaymentStatus = NewPaymentStatus.Failed }; if (!ModelState.IsValid || paymentData == null || paymentData.BankAccountId == null ) { return(PartialView("_NewPaymentPartial", viewModelResult)); } ModelState.Clear(); try { var userId = userManager.GetUserId(User); paymentsService.CreateAccountPayment(userId, paymentData.BankAccountId.Value, paymentData.Amount, paymentData.ExternalName, paymentData.ExternalIBAN, ""); viewModelResult.PaymentMessage = "Done"; viewModelResult.PaymentStatus = NewPaymentStatus.Created; } catch (NotEnoughFundsException) { viewModelResult.PaymentStatus = NewPaymentStatus.Failed; viewModelResult.PaymentMessage = "Not enough funds available"; } catch (Exception e) { logger.LogError("Failed to make payment {@Exception}", e.Message); logger.LogDebug("Failed to see payment {@ExceptionMessage}", e); viewModelResult.PaymentStatus = NewPaymentStatus.Failed; } //return PartialView("_NewPaymentPartial", viewModelResult); return(RedirectToAction("Index")); }