public async Task <IActionResult> GetTransfer(GetTransferViewModel model) { if (!TryValidateModel(model, nameof(model))) { return(View("GetTransfer", model)); } try { TransferModel returnValues = await Mediator.Send(new GetBankTransferCommand() { CNP = model.CNP, Token = model.Token }); ViewTransferViewModel returnModel = new ViewTransferViewModel() { TransactionId = returnValues.Id, Destinatar = returnValues.Destinatar_id, DestinationCurrency = returnValues.DestinationCurrency, FinalAmmount = returnValues.FinalAmmount, InnitialAmmount = returnValues.Ammount, SourceCurrency = returnValues.SourceCurrency }; ViewBag.TokenExpired = false; return(View("ViewTransfer", returnModel)); } catch (Exception e) when(e.InnerException is TokenExpiredException) { ViewBag.TokenExpired = true; return(View("ViewTransfer", new ViewTransferViewModel())); } }
/// <summary> /// Transfers money from one account to another /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <HttpResponseMessage> Transfer(GetTransferViewModel model) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri("http://40.76.130.186"); var response = await client.PostAsJsonAsync("api/transaction/transfer", new { Source_AccountId = model.Source_AccountId, Target_AccountId = model.Target_AccountId, amount = model.amount }); return(response); } }
public IActionResult TransferView(int id) { if (HttpContext.Session.GetString("IsEmployee") == null) { return(RedirectToAction("Login", "Authentication")); } else { GetTransferViewModel model = new GetTransferViewModel() { Source_AccountId = id }; return(View(model)); } }
public async Task <IActionResult> TransferView(GetTransferViewModel model) { if (!ModelState.IsValid) { return(View(model)); } TransactionStatusViewModel transactionStatus = new TransactionStatusViewModel(); try { var response = await _transactionProvider.Transfer(model); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var jsoncontent = await response.Content.ReadAsStringAsync(); transactionStatus = JsonConvert.DeserializeObject <TransactionStatusViewModel>(jsoncontent); return(View("TransactionStatus", transactionStatus)); } else if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { ModelState.AddModelError("", "Transaction Denied,because of overdraft amount!"); return(View("TransferView", model)); } else if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { ViewBag.Message = "Internal Server Error! Please try again later"; return(View("TransferView", model)); } } catch (Exception ex) { _logger.Error("Exceptions Occured as " + ex.Message); } ModelState.AddModelError("", "Having some unexpected error while processing transaction"); return(View(model)); }