private void UpdateTaxRates(List <TaxRateInfo> taxRateInfos) { using (esTransactionScope transaction = new esTransactionScope()) { int storeId = StoreContext.CurrentStore.Id.Value; //---- delete all tax regions for this store TaxRegionQuery q = new TaxRegionQuery(); q.Where(q.StoreId == storeId); TaxRegionCollection taxRegions = new TaxRegionCollection(); taxRegions.Load(q); taxRegions.MarkAllAsDeleted(); taxRegions.Save(); //---- and re-insert them // remove duplicate entries taxRateInfos.RemoveDuplicates((left, right) => (left.CountryCode == right.CountryCode && left.Region == right.Region) ? 1 : -1); foreach (TaxRateInfo taxRate in taxRateInfos) { TaxRegion newTaxRegion = taxRegions.AddNew(); newTaxRegion.StoreId = storeId; newTaxRegion.CountryCode = taxRate.CountryCode; newTaxRegion.Region = taxRate.Region; newTaxRegion.TaxRate = taxRate.TaxRate; } taxRegions.Save(); transaction.Complete(); } }
private void FillListControls() { // drop-down values of country-region //List<ListItem> countries = DnnHelper.GetCountryListItems(); //StringBuilder html = new StringBuilder("<option></option>"); //foreach(ListItem countryItem in countries) //{ // List<ListItem> regionsForCountry = DnnHelper.GetRegionListItems(countryItem.Value); // if(regionsForCountry.Count > 0) // { // foreach(ListItem regionItem in regionsForCountry) // { // html.AppendFormat(@"<option value=""{0}-{1}"">{2} | {3}</option>", countryItem.Value, regionItem.Value, countryItem.Text, regionItem.Text); // regionNameHash[regionItem.Value] = regionItem.Text; // } // } // else // { // html.AppendFormat(@"<option value=""{0}"">{1}</option>", countryItem.Value, countryItem.Text); // } // countryNameHash[countryItem.Value] = countryItem.Text; //} //litCountryRegionOptions.Text = html.ToString(); try { rdoChargeTaxBasedOn.SelectedValue = StoreContext.CurrentStore.GetSetting(StoreSettingNames.SalesTaxAddressType); } catch (Exception ex) { } List <CountryInfo> countries = DnnHelper.GetCountryListAdoNet(); StringBuilder html = new StringBuilder(@"<option></option>"); foreach (var country in countries) { if (country.Regions.Count > 0) { //html.AppendFormat(@"<option value=""{0}"">{1}</option>", country.CountryCode, country.Name); foreach (var region in country.Regions.Values) { html.AppendFormat(@"<option value=""{0}-{1}"">{2} | {3}</option>", country.CountryCode, region.RegionCode, country.Name, region.Name); regionNameHash[region.RegionCode] = region.Name; } } else { html.AppendFormat(@"<option value=""{0}"">{1}</option>", country.CountryCode, country.Name); } countryNameHash[country.CountryCode] = country.Name; } litCountryRegionOptions.Text = html.ToString(); // databind the existing tax regions rptTaxRates.DataSource = TaxRegionCollection.GetTaxRegions(StoreContext.CurrentStore.Id.Value); rptTaxRates.DataBind(); }