/// <summary> /// Returns Jurisdiction by code. /// </summary> /// <param name="code">The jurisdiction code.</param> /// <param name="returnAllGroups">True, to return all jurisdiction groups.</param> /// <returns></returns> public static JurisdictionDto GetJurisdiction(string code, bool returnAllGroups) { // Assign new cache key, specific for site guid and response groups requested string cacheKey = OrderCache.CreateCacheKey("jurisdiction-code", code, returnAllGroups.ToString()); JurisdictionDto dto = null; // check cache first object cachedObject = OrderCache.Get(cacheKey); if (cachedObject != null) { dto = (JurisdictionDto)cachedObject; } // Load the object if (dto == null) { DataCommand cmd = OrderDataHelper.CreateConfigDataCommand(); cmd.CommandText = "[ecf_Jurisdiction_JurisdictionCode]"; cmd.Parameters = new DataParameters(); cmd.Parameters.Add(new DataParameter("ApplicationId", OrderConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("JurisdictionCode", code, DataParameterType.NVarChar, 50)); cmd.Parameters.Add(new DataParameter("ReturnAllGroups", returnAllGroups, DataParameterType.Bit)); cmd.DataSet = new JurisdictionDto(); cmd.TableMapping = DataHelper.MapTables("Jurisdiction", "JurisdictionGroup", "JurisdictionRelation"); DataResult results = DataService.LoadDataSet(cmd); dto = (JurisdictionDto)results.DataSet; } return(dto); }
/// <summary> /// Handles the SaveChanges event of the EditSaveControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs"/> instance containing the event data.</param> void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e) { if (!this.Page.IsValid) { e.RunScript = false; return; } JurisdictionDto jurisdiction = (JurisdictionDto)Session[_JurisdictionDtoEditSessionKey]; if (JurisdictionGroupId > 0 && jurisdiction == null) { jurisdiction = JurisdictionManager.GetJurisdictionGroup(JurisdictionGroupId); } else if (JurisdictionGroupId == 0) { jurisdiction = new JurisdictionDto(); } IDictionary context = new ListDictionary(); context.Add(_JurisdictionDtoString, jurisdiction); ViewControl.SaveChanges(context); if (jurisdiction.HasChanges()) { JurisdictionManager.SaveJurisdiction(jurisdiction); } // we don't need to store Dto in session any more Session.Remove(_JurisdictionDtoEditSessionKey); }
/// <summary> /// Binds the jurisdiction groups. /// </summary> private void BindJurisdictionGroups() { while (JurisdictionGroupsList.Items.Count > 1) { JurisdictionGroupsList.Items.RemoveAt(1); } JurisdictionDto jurisdictions = JurisdictionManager.GetJurisdictionGroups(JurisdictionManager.JurisdictionType.Tax); var query = from jurisdictionGroup in jurisdictions.JurisdictionGroup orderby jurisdictionGroup.DisplayName select jurisdictionGroup; foreach (JurisdictionDto.JurisdictionGroupRow groupRow in query) { string filterExpression = String.Format("JurisdictionGroupId = {0} AND TaxValueId <> {1}", groupRow.Field <Int32>("JurisdictionGroupId"), TaxValueId); ListItem li = new ListItem(groupRow.Field <string>("DisplayName"), groupRow.Field <Int32>("JurisdictionGroupId").ToString()); if (groupRow.Field <Int32>("JurisdictionGroupId") != TaxValueId && _Tax.TaxValue.Select(filterExpression).Length > 0) { continue; } JurisdictionGroupsList.Items.Add(li); } JurisdictionGroupsList.DataBind(); }
/// <summary> /// Loads the context. /// </summary> private void LoadContext() { if (JurisdictionGroupId > 0) { JurisdictionDto jurisdiction = null; if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes"))) // load fresh on initial load { jurisdiction = LoadFresh(); } else // load from session { jurisdiction = (JurisdictionDto)Session[_JurisdictionDtoEditSessionKey]; if (jurisdiction == null) { jurisdiction = LoadFresh(); } } // Put a dictionary key that can be used by other tabs IDictionary dic = new ListDictionary(); dic.Add(_JurisdictionDtoString, jurisdiction); // Call tabs load context ViewControl.LoadContext(dic); _Jurisdiction = jurisdiction; } }
/// <summary> /// Gets the line items data source. /// </summary> /// <returns></returns> private object GetTaxValuesDataSource() { if (_Tax != null) { TaxDto.TaxValueRow[] valueRows = null; if (TaxId > 0) { valueRows = (TaxDto.TaxValueRow[])_Tax.TaxValue.Select(String.Format("TaxId={0}", TaxId)); } else { valueRows = (TaxDto.TaxValueRow[])_Tax.TaxValue.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent); } DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[6] { new DataColumn(_GridTaxValueIdString, typeof(int)), new DataColumn(_GridTaxIdString, typeof(int)), new DataColumn(_GridPercentageString, typeof(float)), new DataColumn(_GridTaxCategoryString, typeof(string)), new DataColumn(_GridJurisdictionGroupIdString, typeof(int)), new DataColumn(_GridAffectiveDateString, typeof(DateTime)) }); if (valueRows != null) { foreach (TaxDto.TaxValueRow row in valueRows) { dt.ImportRow(row); } } dt.Columns.Add(new DataColumn(_GridJurisdictionGroupString, typeof(string))); foreach (DataRow row in dt.Rows) { // skip deleted rows if (row.RowState == DataRowState.Deleted) { continue; } JurisdictionDto jurisdictions = JurisdictionManager.GetJurisdictionGroup((int)row[_GridJurisdictionGroupIdString]); if (jurisdictions.JurisdictionGroup.Rows.Count > 0) { row[_GridJurisdictionGroupString] = jurisdictions.JurisdictionGroup[0].DisplayName; } else { row[_GridJurisdictionGroupString] = String.Empty; } } return(dt); } return(null); }
/// <summary> /// Loads the fresh. /// </summary> /// <returns></returns> private JurisdictionDto LoadFresh() { JurisdictionDto jurisdiction = JurisdictionManager.GetJurisdictionGroup(JurisdictionGroupId); // persist in session Session[_JurisdictionDtoEditSessionKey] = jurisdiction; return(jurisdiction); }
/// <summary> /// Loads the data and data bind. /// </summary> /// <param name="sortExpression">The sort expression.</param> private void LoadDataAndDataBind(string sortExpression) { JurisdictionDto dto = JurisdictionManager.GetJurisdictionGroups(JurisdictionType); if (dto.Jurisdiction != null) { DataView view = dto.JurisdictionGroup.DefaultView; view.Sort = sortExpression; MyListView.DataSource = view; } MyListView.CurrentListView.PrimaryKeyId = EcfListView.MakePrimaryKeyIdString("JurisdictionGroupId", "JurisdictionType"); MyListView.DataBind(); }
/// <summary> /// Saves the jurisdiction. /// </summary> /// <param name="dto">The dto.</param> public static void SaveJurisdiction(JurisdictionDto dto) { if (dto == null) { throw new ArgumentNullException("dto", String.Format("JurisdictionDto can not be null")); } DataCommand cmd = OrderDataHelper.CreateConfigDataCommand(); using (TransactionScope scope = new TransactionScope()) { DataHelper.SaveDataSetSimple(OrderContext.MetaDataContext, cmd, dto, "Jurisdiction", "JurisdictionGroup", "JurisdictionRelation"); scope.Complete(); } }
/// <summary> /// Checks if entered code is unique. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Web.UI.WebControls.ServerValidateEventArgs"/> instance containing the event data.</param> public void CodeCheck(object sender, ServerValidateEventArgs args) { // load jurisdiction group by code JurisdictionDto dto = JurisdictionManager.GetJurisdictionGroup(args.Value); // check if jurisdiction group with specified code is loaded if (dto != null && dto.JurisdictionGroup.Count > 0 && dto.JurisdictionGroup[0].JurisdictionGroupId != JurisdictionGroupId && String.Compare(dto.JurisdictionGroup[0].Code, args.Value, StringComparison.CurrentCultureIgnoreCase) == 0) { args.IsValid = false; return; } args.IsValid = true; }
void ProcessDeleteCommand(string[] items) { for (int i = 0; i < items.Length; i++) { string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]); if (keys != null) { int id = Int32.Parse(keys[0]); // delete selected jurisdiction JurisdictionDto dto = JurisdictionManager.GetJurisdiction(id); if (dto != null && dto.Jurisdiction.Count > 0) { dto.Jurisdiction[0].Delete(); JurisdictionManager.SaveJurisdiction(dto); } } } }
/// <summary> /// Binds the data. /// </summary> public void BindData() { if (_ShippingMethodDto != null && _ShippingMethodDto.ShippingMethod.Count > 0) { // bind jurisdiction groups dropdown JurisdictionDto jDto = JurisdictionManager.GetJurisdictionGroups(Mediachase.Commerce.Orders.Managers.JurisdictionManager.JurisdictionType.Shipping); JurisdictionGroupList.DataSource = jDto.JurisdictionGroup; JurisdictionGroupList.DataBind(); EndDate.Value = DateTime.UtcNow.AddYears(1); // bind shipping method cases BindItemsGrid(); } else { this.Visible = false; } }
/// <summary> /// Gets the jurisdictions and jurisdiction groups for the specified jurisdiction type. /// </summary> /// <param name="jurisdictionType">JurisdictionType. 1 - tax, 2 - shipping. null - all jurisdictions.</param> /// <returns></returns> public static JurisdictionDto GetJurisdictions(JurisdictionType?jurisdictionType) { // Assign new cache key, specific for site guid and response groups requested string cacheKey = OrderCache.CreateCacheKey("jurisdictions", jurisdictionType.HasValue ? jurisdictionType.Value.ToString() : String.Empty); JurisdictionDto dto = null; // check cache first object cachedObject = OrderCache.Get(cacheKey); if (cachedObject != null) { dto = (JurisdictionDto)cachedObject; } // Load the object if (dto == null) { DataCommand cmd = OrderDataHelper.CreateConfigDataCommand(); cmd.CommandText = "[ecf_Jurisdiction]"; cmd.Parameters = new DataParameters(); cmd.Parameters.Add(new DataParameter("ApplicationId", OrderConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier)); if (jurisdictionType.HasValue) { cmd.Parameters.Add(new DataParameter("JurisdictionType", jurisdictionType.Value.GetHashCode(), DataParameterType.Int)); } cmd.DataSet = new JurisdictionDto(); cmd.TableMapping = DataHelper.MapTables("Jurisdiction", "JurisdictionGroup", "JurisdictionRelation"); DataResult results = DataService.LoadDataSet(cmd); dto = (JurisdictionDto)results.DataSet; // Insert to the cache collection OrderCache.Insert(cacheKey, dto, OrderConfiguration.Instance.Cache.PaymentCollectionTimeout); } return(dto); }
public void LoadContext(IDictionary context) { _JurisdictionDto = (JurisdictionDto)context[_JurisdictionDtoString]; }
public void SaveChanges(IDictionary context) { JurisdictionDto dto = (JurisdictionDto)context[_JurisdictionDtoString]; JurisdictionDto.JurisdictionGroupRow row = null; if (dto.JurisdictionGroup.Count > 0) { row = dto.JurisdictionGroup[0]; } else { row = dto.JurisdictionGroup.NewJurisdictionGroupRow(); row.JurisdictionType = JurisdictionType.GetHashCode(); } row.ApplicationId = OrderConfiguration.Instance.ApplicationId; row.DisplayName = DisplayName.Text; row.Code = Code.Text; if (row.RowState == DataRowState.Detached) { dto.JurisdictionGroup.Rows.Add(row); } // update jurisdictions in the group // a). delete rows from dto that are not selected bool found = false; foreach (JurisdictionDto.JurisdictionRelationRow rowTmp in row.GetJurisdictionRelationRows()) { found = false; ListItem lItem = JurisdictionsList.LeftItems.FindByValue(rowTmp.JurisdictionId.ToString()); if (lItem != null) { rowTmp.Delete(); } } // b). add selected rows to dto foreach (ListItem item in JurisdictionsList.RightItems) { bool exists = false; foreach (JurisdictionDto.JurisdictionRelationRow rowTmp in row.GetJurisdictionRelationRows()) { if (String.Compare(item.Value, rowTmp.JurisdictionId.ToString(), true) == 0) { exists = true; break; } } // if jurisdiction not in the group, add it if (!exists) { // add jurisdiction to the group JurisdictionDto.JurisdictionRelationRow newRow = dto.JurisdictionRelation.NewJurisdictionRelationRow(); newRow.JurisdictionId = Int32.Parse(item.Value); newRow.JurisdictionGroupId = row.JurisdictionGroupId; // add the row to the dto dto.JurisdictionRelation.Rows.Add(newRow); } } }
/// <summary> /// Binds the jurisdictions list. /// </summary> /// <param name="jurisdictionGroupRow">The jurisdiction group row.</param> private void BindJurisdictionsList(JurisdictionDto.JurisdictionGroupRow jurisdictionGroupRow) { List <JurisdictionDto.JurisdictionRow> leftJurisdictions = new List <JurisdictionDto.JurisdictionRow>(); List <JurisdictionDto.JurisdictionRow> rightJurisdictions = new List <JurisdictionDto.JurisdictionRow>(); JurisdictionManager.JurisdictionType jType = JurisdictionType; if (jurisdictionGroupRow != null) { jType = (JurisdictionManager.JurisdictionType)Enum.Parse(typeof(JurisdictionManager.JurisdictionType), jurisdictionGroupRow.JurisdictionType.ToString()); } JurisdictionDto dto = JurisdictionManager.GetJurisdictions(jType); bool allToLeft = false; // if true, then add all jurisdictions to the left list if (jurisdictionGroupRow != null) { JurisdictionDto.JurisdictionRelationRow[] selectedJurisdictionRows = jurisdictionGroupRow.GetJurisdictionRelationRows(); if (selectedJurisdictionRows != null && selectedJurisdictionRows.Length > 0) { foreach (JurisdictionDto.JurisdictionRow jRow in dto.Jurisdiction) { bool found = false; foreach (JurisdictionDto.JurisdictionRelationRow selectedJurisdictionRow in selectedJurisdictionRows) { if (jRow.JurisdictionId == selectedJurisdictionRow.JurisdictionId) { found = true; break; } } if (found) { rightJurisdictions.Add(jRow); } else { leftJurisdictions.Add(jRow); } } JurisdictionsList.LeftDataSource = leftJurisdictions; JurisdictionsList.RightDataSource = rightJurisdictions; } else { // add all jurisdictions to the left list allToLeft = true; } } else { allToLeft = true; } if (allToLeft) { // add all jurisdictions to the left list JurisdictionsList.LeftDataSource = dto.Jurisdiction; } JurisdictionsList.DataBind(); }
/// <summary> /// Imports the specified input. /// </summary> /// <param name="input">The input.</param> /// <param name="applicationId">The application id.</param> /// <param name="baseFilePath">The base file path.</param> public void Import(string pathToCsvFile, Guid applicationId, Guid?siteId, char delimiter) { CultureInfo currentCultureInfo = GetImportExportCulture(); int totalImportSteps = GetTotalImportSteps(); OnEvent("Starting import...", 0); string fileName = Path.GetFileName(pathToCsvFile); // 1. Parse csv file OnEvent("Start parsing csv file", GetProgressPercent((int)ImportSteps.StartParseFile, totalImportSteps)); CsvIncomingDataParser parser = new CsvIncomingDataParser(Path.GetDirectoryName(pathToCsvFile), true, delimiter); DataSet taxDataSet = parser.Parse(fileName, null); OnEvent("Finished parsing csv file", GetProgressPercent((int)ImportSteps.EndParseFile, totalImportSteps)); // 2. Create Dtos from parsed DataSet if (taxDataSet.Tables[fileName] == null) { throw new OrdersImportExportException(String.Format("Unknown problem with parsing file {0}.", fileName)); } OnEvent("Start processing parsed rows", GetProgressPercent((int)ImportSteps.StartImport, totalImportSteps)); int totalRowCount = taxDataSet.Tables[fileName].Rows.Count; JurisdictionDto currentJurisdictionDto = JurisdictionManager.GetJurisdictions(Mediachase.Commerce.Orders.Managers.JurisdictionManager.JurisdictionType.Tax); TaxDto currentTaxDto = TaxManager.GetTaxDto(TaxType.SalesTax); JurisdictionDto jurisdictionDto = new JurisdictionDto(); TaxDto taxDto = new TaxDto(); for (int i = 0; i <= totalRowCount - 1; i++) { DataRow currentRow = taxDataSet.Tables[fileName].Rows[i]; #region Import Jurisdictions #region JurisdictionDto string jurisdictionCode = currentRow.ItemArray.GetValue(9).ToString(); JurisdictionDto.JurisdictionRow jRow = null; JurisdictionDto.JurisdictionRow[] jRows = (JurisdictionDto.JurisdictionRow[])currentJurisdictionDto.Jurisdiction.Select(String.Format("Code='{0}'", jurisdictionCode)); // check if row has already been imported // (to support multiple values for the same jurisdiction need to check if jurisdiction with the given name already exists in jurisdictionDto) JurisdictionDto.JurisdictionRow[] jRows2 = (JurisdictionDto.JurisdictionRow[])jurisdictionDto.Jurisdiction.Select(String.Format("Code='{0}'", jurisdictionCode)); bool jurisdictionExists = jRows2 != null && jRows2.Length > 0; if (jurisdictionExists) { jRow = jRows2[0]; } else { if (jRows != null && jRows.Length > 0) { jurisdictionDto.Jurisdiction.ImportRow(jRows[0]); jRow = jurisdictionDto.Jurisdiction[jurisdictionDto.Jurisdiction.Count - 1]; } else { jRow = jurisdictionDto.Jurisdiction.NewJurisdictionRow(); jRow.ApplicationId = applicationId; jRow.JurisdictionType = Mediachase.Commerce.Orders.Managers.JurisdictionManager.JurisdictionType.Tax.GetHashCode(); } } jRow.DisplayName = currentRow.ItemArray.GetValue(0).ToString(); jRow.StateProvinceCode = GetStringValue(currentRow.ItemArray.GetValue(1)); jRow.CountryCode = currentRow.ItemArray.GetValue(2).ToString(); jRow.ZipPostalCodeStart = GetStringValue(currentRow.ItemArray.GetValue(3)); jRow.ZipPostalCodeEnd = GetStringValue(currentRow.ItemArray.GetValue(4)); jRow.City = GetStringValue(currentRow.ItemArray.GetValue(5)); jRow.District = GetStringValue(currentRow.ItemArray.GetValue(6)); jRow.County = GetStringValue(currentRow.ItemArray.GetValue(7)); jRow.GeoCode = GetStringValue(currentRow.ItemArray.GetValue(8)); jRow.Code = jurisdictionCode; if (jRow.RowState == DataRowState.Detached) { jurisdictionDto.Jurisdiction.Rows.Add(jRow); } #endregion #region JurisdictionGroupDto string jurisdictionGroupCode = currentRow.ItemArray.GetValue(11).ToString(); JurisdictionDto.JurisdictionGroupRow jGroupRow = null; JurisdictionDto.JurisdictionGroupRow[] jGroupRows = (JurisdictionDto.JurisdictionGroupRow[])currentJurisdictionDto.JurisdictionGroup.Select(String.Format("Code='{0}'", jurisdictionGroupCode)); // check if row has already been imported // (to support multiple values for the same jurisdiction need to check if jurisdiction with the given name already exists in jurisdictionDto) JurisdictionDto.JurisdictionGroupRow[] jGroupRows2 = (JurisdictionDto.JurisdictionGroupRow[])jurisdictionDto.JurisdictionGroup.Select(String.Format("Code='{0}'", jurisdictionGroupCode)); bool jurisdictionGroupExists = jGroupRows2 != null && jGroupRows2.Length > 0; if (jurisdictionGroupExists) { jGroupRow = jGroupRows2[0]; } else { if (jGroupRows != null && jGroupRows.Length > 0) { jurisdictionDto.JurisdictionGroup.ImportRow(jGroupRows[0]); jGroupRow = jurisdictionDto.JurisdictionGroup[jurisdictionDto.JurisdictionGroup.Count - 1]; } else { jGroupRow = jurisdictionDto.JurisdictionGroup.NewJurisdictionGroupRow(); jGroupRow.ApplicationId = applicationId; jGroupRow.JurisdictionType = Mediachase.Commerce.Orders.Managers.JurisdictionManager.JurisdictionType.Tax.GetHashCode(); } } jGroupRow.DisplayName = currentRow.ItemArray.GetValue(10).ToString(); jGroupRow.Code = jurisdictionGroupCode; if (jGroupRow.RowState == DataRowState.Detached) { jurisdictionDto.JurisdictionGroup.Rows.Add(jGroupRow); } #endregion #region JurisdictionRelationDto JurisdictionDto.JurisdictionRelationRow jRelationRow = null; if (jRow.JurisdictionId > 0 && jGroupRow.JurisdictionGroupId > 0) { // check if relation already exists JurisdictionDto.JurisdictionRelationRow[] jRelationRows = (JurisdictionDto.JurisdictionRelationRow[])currentJurisdictionDto.JurisdictionRelation.Select(String.Format("JurisdictionId={0} AND JurisdictionGroupId={1}", jRow.JurisdictionId, jGroupRow.JurisdictionGroupId)); if (jRelationRows != null && jRelationRows.Length > 0) { jurisdictionDto.JurisdictionRelation.ImportRow(jRelationRows[0]); jRelationRow = jurisdictionDto.JurisdictionRelation[jurisdictionDto.JurisdictionRelation.Count - 1]; } } if (jRelationRow == null) { // create new relation jRelationRow = jurisdictionDto.JurisdictionRelation.NewJurisdictionRelationRow(); jRelationRow.JurisdictionId = jRow.JurisdictionId; jRelationRow.JurisdictionGroupId = jGroupRow.JurisdictionGroupId; jurisdictionDto.JurisdictionRelation.Rows.Add(jRelationRow); } #endregion // save jurisdictionDto if (jurisdictionDto.HasChanges()) { JurisdictionManager.SaveJurisdiction(jurisdictionDto); } #endregion #region Import Taxes #region TaxDto TaxDto.TaxRow taxRow = null; string taxName = currentRow.ItemArray.GetValue(13).ToString(); // check if row already exists TaxDto.TaxRow[] taxRows = (TaxDto.TaxRow[])currentTaxDto.Tax.Select(String.Format("Name='{0}'", taxName)); // check if row has already been imported TaxDto.TaxRow[] taxRows2 = (TaxDto.TaxRow[])taxDto.Tax.Select(String.Format("Name='{0}'", taxName)); bool taxExists = taxRows2 != null && taxRows2.Length > 0; if (taxExists) { taxRow = taxRows2[0]; } else { #region if tax is not in the destination dto if (taxRows != null && taxRows.Length > 0) { taxDto.Tax.ImportRow(taxRows[0]); taxRow = taxDto.Tax[taxDto.Tax.Count - 1]; } else { taxRow = taxDto.Tax.NewTaxRow(); taxRow.ApplicationId = applicationId; taxRow.TaxType = TaxType.SalesTax.GetHashCode(); taxRow.Name = taxName; } #endregion } taxRow.SortOrder = Int32.Parse(currentRow.ItemArray.GetValue(14).ToString()); if (taxRow.RowState == DataRowState.Detached) { taxDto.Tax.Rows.Add(taxRow); } #endregion #region TaxLanguageDto TaxDto.TaxLanguageRow taxLanguageRow = null; string langCode = currentRow.ItemArray.GetValue(15).ToString(); // check if row already exists TaxDto.TaxLanguageRow[] taxLanguageRows = (TaxDto.TaxLanguageRow[])currentTaxDto.TaxLanguage.Select(String.Format("LanguageCode='{0}' and TaxId={1}", langCode, taxRow.TaxId)); // check if row has already been imported TaxDto.TaxLanguageRow[] taxLanguageRows2 = (TaxDto.TaxLanguageRow[])taxDto.TaxLanguage.Select(String.Format("LanguageCode='{0}' and TaxId={1}", langCode, taxRow.TaxId)); bool taxLanguageExists = taxLanguageRows2 != null && taxLanguageRows2.Length > 0; string displayName = currentRow.ItemArray.GetValue(12).ToString(); if (taxLanguageExists) { taxLanguageRow = taxLanguageRows2[0]; } else { #region if tax is not in the destination dto if (taxLanguageRows != null && taxLanguageRows.Length > 0) { taxDto.TaxLanguage.ImportRow(taxLanguageRows[0]); taxLanguageRow = taxDto.TaxLanguage[taxDto.TaxLanguage.Count - 1]; } else { taxLanguageRow = taxDto.TaxLanguage.NewTaxLanguageRow(); taxLanguageRow.LanguageCode = langCode; taxLanguageRow.TaxId = taxRow.TaxId; } #endregion } taxLanguageRow.DisplayName = displayName; if (taxLanguageRow.RowState == DataRowState.Detached) { taxDto.TaxLanguage.Rows.Add(taxLanguageRow); } #endregion #region TaxValueDto TaxDto.TaxValueRow taxValueRow = null; // check if row already exists TaxDto.TaxValueRow[] taxValueRows = null; if (siteId.HasValue) { taxValueRows = (TaxDto.TaxValueRow[])currentTaxDto.TaxValue.Select(String.Format("TaxId={0} and SiteId={1} and JurisdictionGroupId={2}", taxRow.TaxId, siteId.Value, jRelationRow.JurisdictionGroupId)); } else { taxValueRows = (TaxDto.TaxValueRow[])currentTaxDto.TaxValue.Select(String.Format("TaxId={0} and JurisdictionGroupId={1}", taxRow.TaxId, jRelationRow.JurisdictionGroupId)); } // check if row has already been imported TaxDto.TaxValueRow[] taxValueRows2 = null; if (siteId.HasValue) { taxValueRows2 = (TaxDto.TaxValueRow[])taxDto.TaxValue.Select(String.Format("TaxId={0} and SiteId={1} and JurisdictionGroupId={2}", taxRow.TaxId, siteId.Value, jRelationRow.JurisdictionGroupId)); } else { taxValueRows2 = (TaxDto.TaxValueRow[])taxDto.TaxValue.Select(String.Format("TaxId={0} and JurisdictionGroupId={1}", taxRow.TaxId, jRelationRow.JurisdictionGroupId)); } bool taxValueExists = taxValueRows2 != null && taxValueRows2.Length > 0; if (taxValueExists) { taxValueRow = taxValueRows2[0]; } else { if (taxValueRows != null && taxValueRows.Length > 0) { taxDto.TaxValue.ImportRow(taxValueRows[0]); taxValueRow = taxDto.TaxValue[taxDto.TaxValue.Count - 1]; } else { taxValueRow = taxDto.TaxValue.NewTaxValueRow(); taxValueRow.TaxId = taxRow.TaxId; } } // assign tax values taxValueRow.JurisdictionGroupId = jGroupRow.JurisdictionGroupId; taxValueRow.TaxCategory = currentRow.ItemArray.GetValue(16).ToString(); taxValueRow.Percentage = float.Parse(currentRow.ItemArray.GetValue(17).ToString(), currentCultureInfo); taxValueRow.AffectiveDate = DateTime.Parse(currentRow.ItemArray.GetValue(18).ToString(), currentCultureInfo); if (siteId.HasValue) { taxValueRow.SiteId = siteId.Value; } // add row to dto, if needed if (taxValueRow.RowState == DataRowState.Detached) { taxDto.TaxValue.Rows.Add(taxValueRow); } // create tax category, if it doesn't exist yet CatalogTaxManager.CreateTaxCategory(taxValueRow.TaxCategory, true); #endregion if (taxDto.HasChanges()) { TaxManager.SaveTax(taxDto); } #endregion if ((i + 1) % 20 == 0) { OnEvent(String.Format("Processed {0} of {1} rows", i + 1, totalRowCount), GetProgressPercent((int)ImportSteps.StartImport, totalImportSteps)); } } OnEvent(String.Format("Finished processing parsed rows. Total processed: {0}", totalRowCount), GetProgressPercent((int)ImportSteps.Finish, totalImportSteps)); OnEvent("CSV file successfully imported.", 100); }
public void Dump() { var languageBranch = _languageBranchRepository.ListAll().First(); var taxCategory = CatalogTaxManager.CreateTaxCategory("Tax category", true); CatalogTaxManager.SaveTaxCategory(taxCategory); var jurisdictionDto = new JurisdictionDto(); var applicationId = AppContext.Current.ApplicationId; jurisdictionDto.Jurisdiction.AddJurisdictionRow("Jurisdiction", null, languageBranch.LanguageID, (int)JurisdictionManager.JurisdictionType.Tax, null, null, null, null, null, null, applicationId, "ABC"); jurisdictionDto.JurisdictionGroup.AddJurisdictionGroupRow(applicationId, "Group", (int)JurisdictionManager.JurisdictionType.Tax, "ABC"); JurisdictionManager.SaveJurisdiction(jurisdictionDto); var taxDto = new TaxDto(); taxDto.Tax.AddTaxRow((int)TaxType.SalesTax, "Tax", 1, applicationId); taxDto.TaxValue.AddTaxValueRow(20d, taxDto.Tax[0], "Tax category", jurisdictionDto.JurisdictionGroup[0].JurisdictionGroupId, DateTime.Now, Guid.Empty); TaxManager.SaveTax(taxDto); var currentMarket = _currentMarket.GetCurrentMarket(); var market = (MarketImpl)_marketService.GetMarket(currentMarket.MarketId); market.DefaultCurrency = Currency.EUR; market.DefaultLanguage = languageBranch.Culture; _marketService.UpdateMarket(market); var rootLink = _referenceConverter.GetRootLink(); var catalog = _contentRepository.GetDefault <CatalogContent>(rootLink, languageBranch.Culture); catalog.Name = "Catalog"; catalog.DefaultCurrency = market.DefaultCurrency; catalog.CatalogLanguages = new ItemCollection <string> { languageBranch.LanguageID }; catalog.DefaultLanguage = "en"; catalog.WeightBase = "kg"; catalog.LengthBase = "cm"; var catalogRef = _contentRepository.Save(catalog, SaveAction.Publish, AccessLevel.NoAccess); var category = _contentRepository.GetDefault <NodeContent>(catalogRef); category.Name = "Category"; category.DisplayName = "Category"; category.Code = "category"; var categoryRef = _contentRepository.Save(category, SaveAction.Publish, AccessLevel.NoAccess); var product = _contentRepository.GetDefault <ProductContent>(categoryRef); product.Name = "Product"; product.DisplayName = "Product"; product.Code = "product"; var productRef = _contentRepository.Save(product, SaveAction.Publish, AccessLevel.NoAccess); var variant = _contentRepository.GetDefault <VariationContent>(productRef); variant.Name = "Variant"; variant.DisplayName = "Variant"; variant.Code = Constants.VariationCode; variant.TaxCategoryId = taxCategory.TaxCategory.First().TaxCategoryId; variant.MinQuantity = 1; variant.MaxQuantity = 100; _contentRepository.Save(variant, SaveAction.Publish, AccessLevel.NoAccess); var price = new PriceValue { UnitPrice = new Money(100, market.DefaultCurrency), CatalogKey = new CatalogKey(applicationId, variant.Code), MarketId = market.MarketId, ValidFrom = DateTime.Today.AddYears(-1), ValidUntil = DateTime.Today.AddYears(1), CustomerPricing = CustomerPricing.AllCustomers, MinQuantity = 0 }; _priceService.SetCatalogEntryPrices(price.CatalogKey, new[] { price }); var campaign = _contentRepository.GetDefault <SalesCampaign>(SalesCampaignFolder.CampaignRoot); campaign.Name = "QuickSilver"; campaign.Created = DateTime.UtcNow.AddHours(-1); campaign.IsActive = true; campaign.ValidFrom = DateTime.Today; campaign.ValidUntil = DateTime.Today.AddYears(1); var campaignRef = _contentRepository.Save(campaign, SaveAction.Publish, AccessLevel.NoAccess); var promotion = _contentRepository.GetDefault <BuyFromCategoryGetItemDiscount>(campaignRef); promotion.IsActive = true; promotion.Name = "25 % off"; promotion.Category = categoryRef; promotion.Discount.UseAmounts = false; promotion.Discount.Percentage = 25m; _contentRepository.Save(promotion, SaveAction.Publish, AccessLevel.NoAccess); var paymentDto = new PaymentMethodDto(); var created = DateTime.UtcNow.AddHours(-1); paymentDto.PaymentMethod.AddPaymentMethodRow(Constants.PaymentMethodId, "Payment", "Payment", languageBranch.LanguageID, "Keyword", true, true, typeof(GenericPaymentGateway).AssemblyQualifiedName, typeof(OtherPayment).AssemblyQualifiedName, false, 1, created, created, applicationId); paymentDto.MarketPaymentMethods.AddMarketPaymentMethodsRow(market.MarketId.Value, paymentDto.PaymentMethod[0]); PaymentManager.SavePayment(paymentDto); }
public void SaveChanges(IDictionary context) { JurisdictionDto dto = (JurisdictionDto)context[_JurisdictionDtoString]; JurisdictionDto.JurisdictionRow row = null; if (dto.Jurisdiction.Count > 0) { row = dto.Jurisdiction[0]; } else { row = dto.Jurisdiction.NewJurisdictionRow(); row.JurisdictionType = JurisdictionType.GetHashCode(); } row.ApplicationId = OrderConfiguration.Instance.ApplicationId; row.DisplayName = DisplayName.Text; row.Code = Code.Text; if (CountryCode.Text.Trim() == String.Empty) { row.CountryCode = null; } else { row.CountryCode = CountryCode.Text; } if (StateProvinceCode.Text.Trim() == String.Empty) { row.StateProvinceCode = null; } else { row.StateProvinceCode = StateProvinceCode.Text; } if (ZipCodeStart.Text.Trim() == String.Empty) { row.ZipPostalCodeStart = null; } else { row.ZipPostalCodeStart = ZipCodeStart.Text; } row.ZipPostalCodeEnd = ZipCodeEnd.Text; if (City.Text.Trim() == String.Empty) { row.City = null; } else { row.City = City.Text; } if (District.Text.Trim() == String.Empty) { row.District = null; } else { row.District = District.Text; } if (County.Text.Trim() == String.Empty) { row.County = null; } else { row.County = County.Text; } if (GeoCode.Text.Trim() == String.Empty) { row.GeoCode = null; } else { row.GeoCode = GeoCode.Text; } if (row.RowState == DataRowState.Detached) { dto.Jurisdiction.Rows.Add(row); } }