/// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            ShippingMethodDto dto = (ShippingMethodDto)context[_ShippingMethodDtoString];

            if (dto == null)
            {
                // dto must be created in base shipping control that holds tabs
                return;
            }

            ShippingMethodDto.ShippingMethodRow shippingRow = null;

            // create the row if it doesn't exist; or update its modified date if it exists
            if (dto.ShippingMethod.Count > 0)
            {
                shippingRow = dto.ShippingMethod[0];
            }
            else
            {
                return;
            }

            // 1. populate countries

            // a). delete rows from dto that are not selected
            foreach (ShippingMethodDto.ShippingCountryRow row in shippingRow.GetShippingCountryRows())
            {
                bool found = false;
                foreach (ListItem item in CountryList.RightItems)
                {
                    if (String.Compare(item.Value, row.CountryId.ToString(), true) == 0)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    row.Delete();
                }
            }

            // b). add selected rows to dto
            foreach (ListItem item in CountryList.RightItems)
            {
                bool exists = false;
                foreach (ShippingMethodDto.ShippingCountryRow row in shippingRow.GetShippingCountryRows())
                {
                    if (String.Compare(item.Value, row.CountryId.ToString(), true) == 0)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    ShippingMethodDto.ShippingCountryRow restrictedRow = dto.ShippingCountry.NewShippingCountryRow();
                    restrictedRow.CountryId        = Int32.Parse(item.Value);
                    restrictedRow.ShippingMethodId = shippingRow.ShippingMethodId;

                    // add the row to the dto
                    dto.ShippingCountry.Rows.Add(restrictedRow);
                }
            }


            // 2. populate regions

            // a). delete rows from dto that are not selected
            foreach (ShippingMethodDto.ShippingRegionRow row in shippingRow.GetShippingRegionRows())
            {
                bool found = false;
                foreach (ListItem item in RegionList.RightItems)
                {
                    if (String.Compare(item.Value, row.StateProvinceId.ToString(), true) == 0)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    row.Delete();
                }
            }

            // b). add selected rows to dto
            foreach (ListItem item in RegionList.RightItems)
            {
                bool exists = false;
                foreach (ShippingMethodDto.ShippingRegionRow row in shippingRow.GetShippingRegionRows())
                {
                    if (String.Compare(item.Value, row.StateProvinceId.ToString(), true) == 0)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    ShippingMethodDto.ShippingRegionRow restrictedRow = dto.ShippingRegion.NewShippingRegionRow();
                    restrictedRow.StateProvinceId  = Int32.Parse(item.Value);
                    restrictedRow.ShippingMethodId = shippingRow.ShippingMethodId;

                    // add the row to the dto
                    dto.ShippingRegion.Rows.Add(restrictedRow);
                }
            }

            // 3. populate payments restrictions

            // a). delete rows from dto that are not selected
            foreach (ShippingMethodDto.ShippingPaymentRestrictionRow row in shippingRow.GetShippingPaymentRestrictionRows())
            {
                bool found = false;
                foreach (ListItem item in PaymentsList.RightItems)
                {
                    if (String.Compare(item.Value, row.PaymentMethodId.ToString(), true) == 0 && !row.RestrictShippingMethods)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    row.Delete();
                }
            }

            // b). add selected rows to dto
            foreach (ListItem item in PaymentsList.RightItems)
            {
                bool exists = false;
                foreach (ShippingMethodDto.ShippingPaymentRestrictionRow row in shippingRow.GetShippingPaymentRestrictionRows())
                {
                    if (String.Compare(item.Value, row.PaymentMethodId.ToString(), true) == 0 && !row.RestrictShippingMethods)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    ShippingMethodDto.ShippingPaymentRestrictionRow restrictedRow = dto.ShippingPaymentRestriction.NewShippingPaymentRestrictionRow();
                    restrictedRow.PaymentMethodId         = new Guid(item.Value);
                    restrictedRow.ShippingMethodId        = shippingRow.ShippingMethodId;
                    restrictedRow.RestrictShippingMethods = false;

                    // add the row to the dto
                    dto.ShippingPaymentRestriction.Rows.Add(restrictedRow);
                }
            }
        }
        /// <summary>
        /// Binds the payments list.
        /// </summary>
        /// <param name="shippingRow">The shipping row.</param>
        private void BindPaymentsList(ShippingMethodDto.ShippingMethodRow shippingRow)
        {
            List <PaymentMethodDto.PaymentMethodRow> leftPayments  = new List <PaymentMethodDto.PaymentMethodRow>();
            List <PaymentMethodDto.PaymentMethodRow> rightPayments = new List <PaymentMethodDto.PaymentMethodRow>();

            PaymentMethodDto dto = PaymentManager.GetPaymentMethods(shippingRow != null ? shippingRow.LanguageId : LanguageCode, true);

            bool allToLeft = false;             // if true, then add all payments to the left list

            if (shippingRow != null)
            {
                ShippingMethodDto.ShippingPaymentRestrictionRow[] restrictedPaymentRows = shippingRow.GetShippingPaymentRestrictionRows();
                if (restrictedPaymentRows != null && restrictedPaymentRows.Length > 0)
                {
                    foreach (PaymentMethodDto.PaymentMethodRow paymentMethodRow in dto.PaymentMethod)
                    {
                        bool found = false;
                        foreach (ShippingMethodDto.ShippingPaymentRestrictionRow restrictedPaymentRow in restrictedPaymentRows)
                        {
                            if (paymentMethodRow.PaymentMethodId == restrictedPaymentRow.PaymentMethodId)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            rightPayments.Add(paymentMethodRow);
                        }
                        else
                        {
                            leftPayments.Add(paymentMethodRow);
                        }
                    }

                    PaymentsList.LeftDataSource  = leftPayments;
                    PaymentsList.RightDataSource = rightPayments;
                }
                else
                {
                    // add all payments to the left list
                    allToLeft = true;
                }
            }
            else
            {
                allToLeft = true;
            }

            if (allToLeft)
            {
                // add all payments to the left list
                PaymentsList.LeftDataSource = dto.PaymentMethod;
            }

            PaymentsList.DataBind();
        }