public async Task <IActionResult> MakeMerchantDeposit(MakeMerchantDepositViewModel viewModel, CancellationToken cancellationToken) { // Validate the model if (this.ValidateModel(viewModel)) { try { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); MakeMerchantDepositModel makeMerchantDepositModel = this.ViewModelFactory.ConvertFrom(viewModel); // All good with model, call the client to create the golf club MakeMerchantDepositResponseModel makeMerchantDepositResponseModel = await this.ApiClient.MakeMerchantDeposit(accessToken, this.User.Identity as ClaimsIdentity, Guid.Parse(viewModel.MerchantId), makeMerchantDepositModel, cancellationToken); // Merchant Created, redirect to the Merchant List screen return(this.RedirectToAction("GetMerchantList", "Merchant") .WithSuccess("Deposit Successful", $"Deposit made successfully for Merchant - {viewModel.MerchantName}")); } catch (Exception e) { return(this.RedirectToAction("MakeMerchantDeposit", "Merchant") .WithWarning("Deposit Unsuccessful", Helpers.BuildUserErrorMessage("Deposit made successfully for Merchant - {viewModel.MerchantName}"))); } } // If we got this far, something failed, redisplay form return(this.View("MakeMerchantDeposit", viewModel)); }
/// <summary> /// Converts from. /// </summary> /// <param name="makeMerchantDepositViewModel">The make merchant deposit view model.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">makeMerchantDepositViewModel</exception> public MakeMerchantDepositModel ConvertFrom(MakeMerchantDepositViewModel makeMerchantDepositViewModel) { if (makeMerchantDepositViewModel == null) { throw new ArgumentNullException(nameof(makeMerchantDepositViewModel)); } MakeMerchantDepositModel makeMerchantDepositModel = new MakeMerchantDepositModel(); makeMerchantDepositModel.DepositDateTime = DateTime.ParseExact(makeMerchantDepositViewModel.DepositDate, "dd/MM/yyyy", null); makeMerchantDepositModel.Amount = decimal.Parse(makeMerchantDepositViewModel.Amount); makeMerchantDepositModel.Reference = makeMerchantDepositViewModel.Reference; makeMerchantDepositModel.MerchantId = Guid.Parse(makeMerchantDepositViewModel.MerchantId); return(makeMerchantDepositModel); }