public async Task <ActionResult> AddOrEditMarkupDialog(AddOrEditMarkupDialogViewModel vm) { var markup = new MarkupResponse(); if (!string.IsNullOrEmpty(vm.AssetPairId) && vm.SelectedMerchant == "Default") { markup = await _payInternalClient.GetDefaultMarkupAsync(vm.AssetPairId); } else if (!string.IsNullOrEmpty(vm.AssetPairId)) { markup = await _payInternalClient.GetMarkupForMerchantAsync(vm.SelectedMerchant, vm.AssetPairId); } var viewmodel = new AddOrEditMarkupDialogViewModel() { SelectedMerchant = vm.SelectedMerchant, AssetPairId = vm.AssetPairId, DeltaSpread = markup.DeltaSpread, FixedFee = markup.FixedFee, Percent = markup.Percent, Pips = markup.Pips, PriceAssetPairId = markup.PriceAssetPairId, PriceMethod = Enum.GetValues(typeof(PriceMethod)).Cast <PriceMethod>().ToList(), SelectedPriceMethod = markup.PriceMethod.ToString(), IsEditMode = !string.IsNullOrEmpty(vm.AssetPairId) }; return(View(viewmodel)); }
public async Task <ActionResult> AddOrEditMarkup(AddOrEditMarkupDialogViewModel vm) { if (string.IsNullOrEmpty(vm.AssetPairId)) { return(this.JsonFailResult("AssetPairId required", ErrorMessageAnchor)); } if (!vm.IsEditMode) { var markup = new MarkupResponse(); try { if (!string.IsNullOrEmpty(vm.AssetPairId) && vm.SelectedMerchant == "Default") { markup = await _payInternalClient.GetDefaultMarkupAsync(vm.AssetPairId); } else if (!string.IsNullOrEmpty(vm.AssetPairId)) { markup = await _payInternalClient.GetMarkupForMerchantAsync(vm.SelectedMerchant, vm.AssetPairId); } } catch (DefaultErrorResponseException ex) { markup = null; } if (markup != null) { return(this.JsonFailResult("Markup exist: " + markup.AssetPairId, ErrorMessageAnchor)); } } var request = new UpdateMarkupRequest(); request.DeltaSpread = vm.DeltaSpread; request.FixedFee = vm.FixedFee; request.Percent = vm.Percent; request.Pips = vm.Pips; request.PriceAssetPairId = vm.PriceAssetPairId; var pricemethod = PriceMethod.None; Enum.TryParse <PriceMethod>(vm.SelectedPriceMethod, out pricemethod); request.PriceMethod = pricemethod; try { if (string.IsNullOrEmpty(vm.SelectedMerchant) || vm.SelectedMerchant == "Default") { await _payInternalClient.SetDefaultMarkupAsync(vm.AssetPairId, request); } else { await _payInternalClient.SetMarkupForMerchantAsync(vm.SelectedMerchant, vm.AssetPairId, request); } return(this.JsonRequestResult("#markupsList", Url.Action("MarkupsList"), new StaffsPageViewModel() { SelectedMerchant = vm.SelectedMerchant })); } catch (DefaultErrorResponseException ex) { return(this.JsonFailResult("Error: " + ex.Error.ErrorMessage, ErrorMessageAnchor)); } }