public async Task <IActionResult> AddOrEditMerchantTransferSetting(AddOrEditMerchantTransferSettingsDialog vm) { try { JObject ruleInput = string.IsNullOrEmpty(vm.RuleInput?.Trim()) ? null : JObject.Parse(vm.RuleInput); if (vm.IsNew) { await _payTransferValidationClient.Config.AddAsync(new AddLineModel { MerchantId = vm.MerchantId, RuleId = vm.RuleId, RuleInput = ruleInput }); } else { await _payTransferValidationClient.Config.UpdateInputAsync(new UpdateInputModel { MerchantId = vm.MerchantId, RuleId = vm.RuleId, RuleInput = ruleInput }); } } catch (JsonReaderException) { return(this.JsonFailResult("Input must be valid json object", ErrorMessageAnchor)); } catch (ClientApiException e) when(e.HttpStatusCode == HttpStatusCode.BadRequest || e.HttpStatusCode == HttpStatusCode.NotFound) { return(this.JsonFailResult(e.Message, ErrorMessageAnchor)); } catch (ClientApiException e) { _log.Error(e, "PayTransfer API Call error", $"merchantId = {vm.MerchantId}, ruleId = {vm.RuleId}"); return(this.JsonFailResult("Unexpected API call error", ErrorMessageAnchor)); } return(this.JsonRequestResult("#merchantTransferSettingsList", Url.Action("MerchantTransferSettingsList"), new MerchantTransferSettingsListViewModel { SelectedMerchant = vm.MerchantId })); }
public async Task <ActionResult> AddOrEditMerchantTransferSettingDialog(AddOrEditMerchantTransferSettingsDialog vm) { bool isNew = string.IsNullOrEmpty(vm.RuleId); vm.Caption = isNew ? "Add rule" : "Edit rule"; vm.IsNew = isNew; if (isNew) { vm.Enabled = true; } else { ConfigurationModel cfg = await _payTransferValidationClient.Config.GetAsync(vm.MerchantId); vm.RuleInput = cfg.Rules.SingleOrDefault(x => x.RuleId == vm.RuleId)?.RuleInput; } vm.RuleList = await _payTransferValidationClient.Api.GetRegisteredRules(); return(View(vm)); }