/// <summary> /// Saves the object changes. /// </summary> /// <param name="dto">The dto.</param> public void SaveChanges(object dto) { if (Visible) { _PaymentMethodDto = dto as PaymentMethodDto; if (_PaymentMethodDto != null && _PaymentMethodDto.PaymentMethodParameter != null) { var gateway = GetGateways().GetGatewayById(Gateways.SelectedValue); var paymentMethodId = Guid.Empty; if (_PaymentMethodDto.PaymentMethod.Count > 0) { paymentMethodId = _PaymentMethodDto.PaymentMethod[0].PaymentMethodId; } // add new parameters var paramsFilter = new StringBuilder(); if (gateway.Properties != null) { foreach (var prop in gateway.Properties) { var ctrl = GenericTable.FindControl(prop.Name); if (ctrl != null) { var val = ((TextBox)ctrl).Text; var row = GetParameterByName(prop.Name); if (row != null) { row.Value = val; } else { CreateParameter(_PaymentMethodDto, prop.Name, val, paymentMethodId); } paramsFilter.AppendFormat("Parameter <> '{0}' AND ", prop.Name); } } } // add gateway parameter var gRow = GetParameterByName(_GatewayParameterName); if (gRow != null) { gRow.Value = Gateways.SelectedValue; } else { CreateParameter(_PaymentMethodDto, _GatewayParameterName, Gateways.SelectedValue, paymentMethodId); } paramsFilter.AppendFormat("Parameter <> '{0}'", _GatewayParameterName); // add transaction type parameter var trRow = GetParameterByName(_TransactionTypeParameterName); if (trRow != null) { trRow.Value = TransactionTypeList.SelectedValue; } else { CreateParameter(_PaymentMethodDto, _TransactionTypeParameterName, TransactionTypeList.SelectedValue, paymentMethodId); } paramsFilter.AppendFormat(" AND Parameter <> '{0}'", _TransactionTypeParameterName); // remove parameters that are not used anymore var filter = paramsFilter.ToString(); var rows = (PaymentMethodDto.PaymentMethodParameterRow[])_PaymentMethodDto.PaymentMethodParameter.Select(filter); if (rows != null && rows.Length > 0) { foreach (var pRow in rows) { pRow.Delete(); } } } } }
/// <summary> /// Saves the object changes. /// </summary> /// <param name="dto">The dto.</param> public void SaveChanges(object dto) { if (this.Visible) { _PaymentMethodDto = dto as PaymentMethodDto; if (_PaymentMethodDto != null && _PaymentMethodDto.PaymentMethodParameter != null) { Gateway gateway = GetGateways().GetGatewayById(Gateways.SelectedValue); Guid paymentMethodId = Guid.Empty; if (_PaymentMethodDto.PaymentMethod.Count > 0) { paymentMethodId = _PaymentMethodDto.PaymentMethod[0].PaymentMethodId; } // add new parameters StringBuilder paramsFilter = new StringBuilder(); if (gateway.Properties != null) { foreach (GatewayProperty prop in gateway.Properties) { System.Web.UI.Control ctrl = GenericTable.FindControl(prop.Name); if (ctrl != null) { string val = ((TextBox)ctrl).Text; PaymentMethodDto.PaymentMethodParameterRow row = GetParameterByName(prop.Name); if (row != null) { row.Value = val; } else { CreateParameter(_PaymentMethodDto, prop.Name, val, paymentMethodId); } paramsFilter.AppendFormat("Parameter <> '{0}' AND ", prop.Name); } } } // add gateway parameter PaymentMethodDto.PaymentMethodParameterRow gRow = GetParameterByName(_GatewayParameterName); if (gRow != null) { gRow.Value = Gateways.SelectedValue; } else { CreateParameter(_PaymentMethodDto, _GatewayParameterName, Gateways.SelectedValue, paymentMethodId); } paramsFilter.AppendFormat("Parameter <> '{0}'", _GatewayParameterName); // remove parameters that are not used anymore string filter = paramsFilter.ToString(); PaymentMethodDto.PaymentMethodParameterRow[] rows = (PaymentMethodDto.PaymentMethodParameterRow[])_PaymentMethodDto.PaymentMethodParameter.Select(filter); if (rows != null && rows.Length > 0) { foreach (PaymentMethodDto.PaymentMethodParameterRow pRow in rows) { pRow.Delete(); } } } } }