예제 #1
0
 /// <summary>
 /// Raises the association updating event.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The <see cref="Mediachase.Commerce.Catalog.Events.AssociationEventArgs"/> instance containing the event data.</param>
 public void RaiseAssociationUpdatingEvent(CatalogAssociationDto sender, AssociationEventArgs args)
 {
     if (AssociationUpdating != null)
     {
         AssociationUpdating(sender, args);
     }
 }
예제 #2
0
        /// <summary>
        /// Creates the empty dtos.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="relation">The relation.</param>
        /// <param name="association">The association.</param>
        /// <param name="persistInSession">if set to <c>true</c> [persist in session].</param>
        private void CreateEmptyDtos(ref CatalogEntryDto entry, ref CatalogRelationDto relation, ref CatalogAssociationDto association, bool persistInSession)
        {
            if (relation == null)
            {
                relation = new CatalogRelationDto();
                if (persistInSession)
                {
                    Session[_CatalogRelationDtoString] = relation;
                }
            }

            if (association == null)
            {
                association = new CatalogAssociationDto();
                if (persistInSession)
                {
                    Session[_CatalogAssociationDtoString] = association;
                }
            }

            if (entry == null)
            {
                entry = new CatalogEntryDto();
                if (persistInSession)
                {
                    Session[_CatalogEntryDtoString] = entry;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the catalog association dto by entry id.
        /// </summary>
        /// <param name="catalogEntryId">The catalog entry id.</param>
        /// <returns></returns>
        internal static CatalogAssociationDto GetCatalogAssociationDtoByEntryId(int catalogEntryId)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = CatalogCache.CreateCacheKey("catalogassociation-catalogEntryId-", catalogEntryId.ToString());

            CatalogAssociationDto dto = null;

            // check cache first
            object cachedObject = CatalogCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (CatalogAssociationDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                CatalogAssociationAdmin admin = new CatalogAssociationAdmin();
                admin.LoadByCatalogEntryId(catalogEntryId);
                dto = admin.CurrentDto;

                // Insert to the cache collection
                CatalogCache.Insert(cacheKey, dto, CatalogConfiguration.Instance.Cache.CatalogCollectionTimeout);
            }

            dto.AcceptChanges();

            return(dto);
        }
예제 #4
0
        /// <summary>
        /// Loads the fresh association.
        /// </summary>
        /// <returns></returns>
        private CatalogAssociationDto LoadFreshAssociation()
        {
            CatalogAssociationDto association = LoadAssociation();

            // persist in session
            Session[_CatalogAssociationDtoString] = association;

            return(association);
        }
예제 #5
0
        /// <summary>
        /// Gets the default association type id.
        /// </summary>
        /// <returns></returns>
        protected string GetDefaultAssociationTypeId()
        {
            CatalogAssociationDto dto = CurrentCatalogAssociationDto;

            if (dto != null && dto.AssociationType.Rows.Count > 0)
            {
                return(((CatalogAssociationDto.AssociationTypeRow)dto.AssociationType.Rows[0]).AssociationTypeId);
            }
            return(String.Empty);
        }
예제 #6
0
        /// <summary>
        /// Saves the catalog association type.
        /// </summary>
        /// <param name="dto">The dto.</param>
        internal static void SaveAssociationType(CatalogAssociationDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto", String.Format("CatalogAssociationDto can not be null"));
            }

            CatalogAssociationAdmin admin = new CatalogAssociationAdmin(dto);

            admin.SaveAssociationType();
        }
예제 #7
0
        /// <summary>
        /// Loads the context.
        /// </summary>
        private void LoadContext()
        {
            CatalogEntryDto       entry       = null;
            CatalogRelationDto    relation    = null;
            CatalogAssociationDto association = null;

            if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes")))             // load fresh on initial load
            {
                entry       = LoadFreshEntry();
                relation    = LoadFreshRelation();
                association = LoadFreshAssociation();

                // if Dtos not loaded, create empty Dtos
                CreateEmptyDtos(ref entry, ref relation, ref association, true);
            }
            else             // load from session
            {
                entry = (CatalogEntryDto)Session[_CatalogEntryDtoString];

                if (entry == null)
                {
                    entry = LoadFreshEntry();
                }

                association = (CatalogAssociationDto)Session[_CatalogAssociationDtoString];

                if (association == null)
                {
                    association = LoadFreshAssociation();
                }

                relation = (CatalogRelationDto)Session[_CatalogRelationDtoString];

                if (relation == null)
                {
                    relation = LoadFreshRelation();
                }
            }

            if (CatalogEntryId > 0 && entry.CatalogEntry.Count == 0)
            {
                Response.Redirect("ContentFrame.aspx?_a=Catalog&_v=Catalog-List");
            }

            // Put a dictionary key that can be used by other tabs
            IDictionary dic = new ListDictionary();

            dic.Add(_CatalogEntryDtoString, entry);
            dic.Add(_CatalogRelationDtoString, relation);
            dic.Add(_CatalogAssociationDtoString, association);

            // Call tabs load context
            ViewControl.LoadContext(dic);
        }
예제 #8
0
        /// <summary>
        /// Gets the association row.
        /// </summary>
        /// <param name="catalogAssociationId">The catalog association id.</param>
        /// <returns></returns>
        private CatalogAssociationDto.CatalogAssociationRow GetAssociationRow(int catalogAssociationId)
        {
            // load selected item
            CatalogAssociationDto dto = CurrentCatalogAssociationDto;

            CatalogAssociationDto.CatalogAssociationRow row = null;
            if (dto != null)
            {
                row = CurrentCatalogAssociationDto.CatalogAssociation.FindByCatalogAssociationId(catalogAssociationId);
            }
            return(row);
        }
예제 #9
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            CatalogAssociationDto dto = (CatalogAssociationDto)context[_CatalogAssociationDtoString];

            /*if (CatalogEntryId > 0 && dto == null)
             *      dto = CatalogContext.Current.GetCatalogAssociationDtoByEntryId(CatalogEntryId);
             * else if (CatalogEntryId == 0)
             *      dto = new CatalogAssociationDto();*/

            dto.CatalogAssociation.Merge(CurrentCatalogAssociationDto.CatalogAssociation, false);
            dto.CatalogEntryAssociation.Merge(CurrentCatalogAssociationDto.CatalogEntryAssociation, false);
        }
예제 #10
0
        /// <summary>
        /// Saves the catalog association.
        /// </summary>
        /// <param name="dto">The dto.</param>
        internal static void SaveCatalogAssociation(CatalogAssociationDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto", String.Format("CatalogAssociationDto can not be null"));
            }

            CatalogAssociationAdmin admin = new CatalogAssociationAdmin(dto);

            EventContext.Instance.RaiseAssociationUpdatingEvent(dto, new AssociationEventArgs("updating"));
            admin.Save();
            EventContext.Instance.RaiseAssociationUpdatedEvent(dto, new AssociationEventArgs("updated"));
        }
예제 #11
0
        /// <summary>
        /// Deletes the entry recursive.
        /// </summary>
        /// <param name="entryId">The entry id.</param>
        /// <param name="parentCatalogId">The parent catalog id.</param>
        private void DeleteEntryRecursive(int entryId, int parentCatalogId)
        {
            CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            if (catalogEntryDto.CatalogEntry.Count > 0)
            {
                //Delete NodeEntryRelation rows
                CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                {
                    if (row.CatalogId == parentCatalogId)
                    {
                        row.Delete();
                    }
                }

                if (catalogRelationDto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);
                }
                else                 //if NodeEntryRelation doesn't exist delete entry
                {
                    //Delete CatalogEntryAssociation rows
                    foreach (CatalogEntryDto.CatalogAssociationRow catalogAssociationRow in catalogEntryDto.CatalogAssociation)
                    {
                        CatalogAssociationDto catalogAssociationDto = FrameworkContext.Current.CatalogSystem.GetCatalogAssociationDto(catalogAssociationRow.CatalogAssociationId);
                        foreach (CatalogAssociationDto.CatalogEntryAssociationRow itemCatalogEntryAssociation in catalogAssociationDto.CatalogEntryAssociation)
                        {
                            itemCatalogEntryAssociation.Delete();
                        }

                        if (catalogAssociationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                        }
                    }

                    //Delete child entry rows
                    CatalogEntryDto childrenDto = CatalogContext.Current.GetCatalogEntriesDto(entryId, String.Empty, String.Empty);
                    foreach (CatalogEntryDto.CatalogEntryRow row in childrenDto.CatalogEntry)
                    {
                        DeleteEntryRecursive(row.CatalogEntryId, 0);
                    }

                    //Delete entry row
                    catalogEntryDto.CatalogEntry[0].Delete();
                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Sets the association items grid data source.
        /// </summary>
        /// <param name="associationId">The association id.</param>
        private void SetAssociationItemsGridDataSource(int associationId)
        {
            CatalogAssociationDto dto = CurrentCatalogAssociationDto;

            CatalogAssociationDto.CatalogAssociationRow row = GetAssociationRow(associationId);

            if (row != null)
            {
                CatalogAssociationDto.CatalogEntryAssociationRow[] entryAssociationRows = row.GetCatalogEntryAssociationRows();
                DataTable dt = new DataTable("CatalogEntryAssociation");
                dt.Columns.AddRange(new DataColumn[5] {
                    new DataColumn(_CatalogAssociationIdString, typeof(int)),
                    new DataColumn(_CatalogEntryIdString, typeof(int)),
                    new DataColumn("EntryName", typeof(string)),
                    new DataColumn(_SortOrderString, typeof(int)),
                    new DataColumn(_AssociationTypeIdString, typeof(string))
                });
                foreach (CatalogAssociationDto.CatalogEntryAssociationRow entryRow in entryAssociationRows)
                {
                    DataRow dr = dt.NewRow();
                    dr[_CatalogAssociationIdString] = entryRow.CatalogAssociationId;
                    dr[_CatalogEntryIdString]       = entryRow.CatalogEntryId;
                    dr["EntryName"]              = GetEntryNameById(entryRow.CatalogEntryId);
                    dr[_SortOrderString]         = entryRow.SortOrder;
                    dr[_AssociationTypeIdString] = entryRow.AssociationTypeId;
                    dt.Rows.Add(dr);
                }

                CatalogAssociationDto.AssociationTypeDataTable  associationTypeTable = new CatalogAssociationDto.AssociationTypeDataTable();
                List <CatalogAssociationDto.AssociationTypeRow> associationTypeRows  = new List <CatalogAssociationDto.AssociationTypeRow>();

                foreach (CatalogAssociationDto.AssociationTypeRow associationTypeRow in dto.AssociationType.Rows)
                {
                    associationTypeTable.ImportRow(associationTypeRow);
                }

                DataSet dsSrc = new DataSet();
                dsSrc.Tables.Add(dt);
                dsSrc.Tables.Add(associationTypeTable);

                dsSrc.Relations.Add(dsSrc.Tables["AssociationType"].Columns["AssociationTypeId"], dsSrc.Tables["CatalogEntryAssociation"].Columns["AssociationTypeId"]);

                AssociationItemsGrid.DataSource = dsSrc;
            }
            else
            {
                AssociationItemsGrid.DataSource = null;
            }
        }
예제 #13
0
        /// <summary>
        /// Loads the items.
        /// </summary>
        /// <param name="iStartIndex">Start index of the i.</param>
        /// <param name="iNumItems">The i num items.</param>
        /// <param name="sFilter">The s filter.</param>
        private void LoadItems(int iStartIndex, int iNumItems, string sFilter)
        {
            AssociationsFilter.Items.Clear();

            CatalogAssociationDto dto = CurrentCatalogAssociationDto;

            CatalogAssociationDto.CatalogAssociationDataTable dtAssociation = dto.CatalogAssociation;

            foreach (CatalogAssociationDto.CatalogAssociationRow assocRow in dto.CatalogAssociation)
            {
                if ((assocRow.RowState & (DataRowState.Added | DataRowState.Modified | DataRowState.Unchanged)) > 0 &&
                    (String.IsNullOrEmpty(sFilter) || assocRow.AssociationName.Contains(sFilter)))
                {
                    ComboBoxItem item = new ComboBoxItem(assocRow.AssociationName);
                    item.Value = assocRow.CatalogAssociationId.ToString();
                    AssociationsFilter.Items.Add(item);
                }
            }

            AssociationsFilter.ItemCount = dto.CatalogAssociation.Count;
        }
예제 #14
0
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnDelete_Click(object sender, EventArgs e)
        {
            CatalogAssociationDto dto = CurrentCatalogAssociationDto;

            if (SelectedAssociationId != 0 && dto != null)
            {
                CatalogAssociationDto.CatalogAssociationRow row = dto.CatalogAssociation.FindByCatalogAssociationId(SelectedAssociationId);
                if (row != null)
                {
                    /*
                     * // delete asosciation items since there's no cascade delete in this relationship
                     * DeleteAssociationItems(row);
                     * */
                    // delete association
                    row.Delete();
                }
            }
            AssociationsFilter.SelectedIndex = -1;
            AssociationsFilter.Text          = "";
            BindForm();
            pnlSelectedAssociation.Visible = false;
        }
예제 #15
0
        /// <summary>
        /// Deletes the catalog.
        /// </summary>
        /// <param name="catalogId">The catalog id.</param>
        public static void DeleteCatalog(int catalogId)
        {
            CatalogDto dto = GetCatalogDto(catalogId, new CatalogResponseGroup(CatalogResponseGroup.ResponseGroup.CatalogFull));

            if (dto.Catalog.Count == 0)
            {
                return;
            }

            //Delete CatalogItemAsset rows by CatalogId
            CatalogNodeDto catalogNodeDto = CatalogNodeManager.GetCatalogNodesDto(catalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.Assets));

            if (catalogNodeDto.CatalogNode.Count > 0)
            {
                for (int i1 = 0; i1 < catalogNodeDto.CatalogItemAsset.Count; i1++)
                {
                    catalogNodeDto.CatalogItemAsset[i1].Delete();
                }

                CatalogNodeManager.SaveCatalogNode(catalogNodeDto);
            }

            // delete relations
            CatalogRelationDto catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(catalogId, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogNode));

            foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
            {
                row.Delete();
            }

            foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows)
            {
                row.Delete();
            }

            foreach (CatalogRelationDto.CatalogNodeRelationRow row in catalogRelationDto.CatalogNodeRelation.Rows)
            {
                row.Delete();
            }

            if (catalogRelationDto.HasChanges())
            {
                CatalogRelationManager.SaveCatalogRelation(catalogRelationDto);
            }

            //Delete CatalogItemSeo rows by CatalogNodeId and CatalogNode rows
            catalogNodeDto = CatalogNodeManager.GetCatalogNodesDto(catalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull));
            if (catalogNodeDto.CatalogNode.Count > 0)
            {
                for (int i1 = 0; i1 < catalogNodeDto.CatalogItemSeo.Count; i1++)
                {
                    catalogNodeDto.CatalogItemSeo[i1].Delete();
                }

                for (int i1 = 0; i1 < catalogNodeDto.CatalogNode.Count; i1++)
                {
                    catalogNodeDto.CatalogNode[i1].Delete();
                }

                CatalogNodeManager.SaveCatalogNode(catalogNodeDto);
            }

            //Delete entries
            while (true)
            {
                CatalogSearchParameters pars    = new CatalogSearchParameters();
                CatalogSearchOptions    options = new CatalogSearchOptions();

                options.Namespace         = String.Empty;
                options.RecordsToRetrieve = 100;
                options.StartingRecord    = 0;
                pars.CatalogNames.Add(dto.Catalog[0].Name);

                int             totalCount      = 0;
                CatalogEntryDto catalogEntryDto = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

                //Delete CatalogEntryAssociation rows
                foreach (CatalogEntryDto.CatalogAssociationRow catalogAssociationRow in catalogEntryDto.CatalogAssociation)
                {
                    CatalogAssociationDto catalogAssociationDto = FrameworkContext.Current.CatalogSystem.GetCatalogAssociationDto(catalogAssociationRow.CatalogAssociationId);
                    foreach (CatalogAssociationDto.CatalogEntryAssociationRow itemCatalogEntryAssociation in catalogAssociationDto.CatalogEntryAssociation)
                    {
                        itemCatalogEntryAssociation.Delete();
                    }

                    if (catalogAssociationDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                    }
                }

                //Delete CatalogEntry rows
                foreach (CatalogEntryDto.CatalogEntryRow catalogEntryRow in catalogEntryDto.CatalogEntry)
                {
                    if (catalogEntryRow.InventoryRow != null)
                    {
                        catalogEntryRow.InventoryRow.Delete();
                    }
                    catalogEntryRow.Delete();
                }

                CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);

                // Break the loop if we retrieved all the record
                if (totalCount < options.RecordsToRetrieve)
                {
                    break;
                }
            }

            // Delete root entries
            CatalogEntryDto rootCatalogEntries = CatalogEntryManager.GetCatalogEntriesDto(catalogId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            foreach (CatalogEntryDto.CatalogEntryRow catalogEntryRow in rootCatalogEntries.CatalogEntry)
            {
                if (catalogEntryRow.InventoryRow != null)
                {
                    catalogEntryRow.InventoryRow.Delete();
                }
                catalogEntryRow.Delete();
            }

            CatalogEntryManager.SaveCatalogEntry(rootCatalogEntries);

            //Delete Catalog row by id
            dto.Catalog[0].Delete();
            SaveCatalog(dto);
        }
 /// <summary>
 /// Loads the context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void LoadContext(IDictionary context)
 {
     _CatalogAssociationDto = (CatalogAssociationDto)context[_CatalogAssociationDtoString];
     _CatalogEntryDto       = (CatalogEntryDto)context[_CatalogEntryDtoString];
 }
예제 #17
0
        /// <summary>
        /// Deletes the entry.
        /// </summary>
        /// <param name="entryId">The entry id.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        internal static void DeleteCatalogEntry(int entryId, bool recursive)
        {
            CatalogEntryDto catalogEntryDto = GetCatalogEntryDto(entryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            if (catalogEntryDto.CatalogEntry.Count > 0)
            {
                if (recursive)
                {
                    //Delete child entry rows
                    CatalogEntryDto childrenDto = GetCatalogEntriesDto(entryId, String.Empty, String.Empty, new CatalogEntryResponseGroup());
                    foreach (CatalogEntryDto.CatalogEntryRow row in childrenDto.CatalogEntry)
                    {
                        DeleteCatalogEntry(row.CatalogEntryId, recursive);
                    }
                }

                CatalogRelationDto catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(0, 0, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));

                //Delete NodeEntryRelation rows
                foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                {
                    row.Delete();
                }

                //Delete CatalogEntryRelation rows
                foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows)
                {
                    row.Delete();
                }

                if (catalogRelationDto.HasChanges())
                {
                    CatalogRelationManager.SaveCatalogRelation(catalogRelationDto);
                }

                //Delete CatalogEntryAssociation rows
                foreach (CatalogEntryDto.CatalogAssociationRow catalogAssociationRow in catalogEntryDto.CatalogAssociation)
                {
                    CatalogAssociationDto catalogAssociationDto = CatalogAssociationManager.GetCatalogAssociationDto(catalogAssociationRow.CatalogAssociationId);
                    foreach (CatalogAssociationDto.CatalogEntryAssociationRow itemCatalogEntryAssociation in catalogAssociationDto.CatalogEntryAssociation)
                    {
                        itemCatalogEntryAssociation.Delete();
                    }

                    if (catalogAssociationDto.HasChanges())
                    {
                        CatalogAssociationManager.SaveCatalogAssociation(catalogAssociationDto);
                    }
                }

                CatalogEntryDto.CatalogEntryRow entryRow = catalogEntryDto.CatalogEntry[0];

                // Delete inventory if on exists
                if (entryRow.InventoryRow != null)
                {
                    entryRow.InventoryRow.Delete();
                }

                //Delete entry row
                entryRow.Delete();
                SaveCatalogEntry(catalogEntryDto);
            }
        }
예제 #18
0
        /// <summary>
        /// Loads the entry.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <param name="responseGroup">The response group.</param>
        /// <param name="entryList">The entry list.</param>
        /// <returns></returns>
        internal static Entry LoadEntry(CatalogEntryDto.CatalogEntryRow row, bool recursive, CatalogEntryResponseGroup responseGroup, ref StringCollection entryList)
        {
            Entry entry = null;

            // Load entry
            if (row != null)
            {
                // Track entries added, to avoid circular dependencies
                entryList.Add(row.Code);

                entry = new Entry(row);

                // Populate association detailed info
                if (recursive && (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Associations)))
                {
                    if (entry.Associations != null)
                    {
                        CatalogAssociationDto associationDto = CatalogAssociationManager.GetCatalogAssociationDtoByEntryId(row.CatalogEntryId);

                        // If associations do not contain any entries, then we do not need to go through the rest
                        if (associationDto.CatalogEntryAssociation.Count > 0)
                        {
                            foreach (Association association in entry.Associations)
                            {
                                int associationId = 0;
                                // Find out association id
                                foreach (CatalogAssociationDto.CatalogAssociationRow associationRow in associationDto.CatalogAssociation)
                                {
                                    if (associationRow.AssociationName.Equals(association.Name))
                                    {
                                        associationId = associationRow.CatalogAssociationId;
                                        break;
                                    }
                                }

                                // Load association entries
                                List <EntryAssociation> entryAssociationList = new List <EntryAssociation>();
                                CatalogEntryDto         associatedEntries    = GetAssociatedCatalogEntriesDto(row.CatalogEntryId, association.Name, responseGroup);
                                foreach (CatalogEntryDto.CatalogEntryRow childRow in associatedEntries.CatalogEntry)
                                {
                                    EntryAssociation entryAssociation = new EntryAssociation();
                                    // Find appropriate row
                                    CatalogAssociationDto.CatalogEntryAssociationRow entryAssociationRow = associationDto.CatalogEntryAssociation.FindByCatalogAssociationIdCatalogEntryId(associationId, childRow.CatalogEntryId);
                                    if (entryAssociationRow != null)
                                    {
                                        entryAssociation.SortOrder       = entryAssociationRow.SortOrder;
                                        entryAssociation.AssociationType = entryAssociationRow.AssociationTypeId;
                                        entryAssociation.AssociationDesc = entryAssociationRow.AssociationTypeRow.Description;
                                    }

                                    // Check for circular dependencies here

                                    /*
                                     * if (row.CatalogEntryId == childRow.CatalogEntryId)
                                     *  throw new CircularDependencyException(String.Format("Circular dependency detected. Entry association \"{0}\" for \"{1}[{2}]\" contains reference to itself.", entryAssociation.AssociationDesc, childRow.Name, childRow.CatalogEntryId));
                                     * */

                                    bool loadRecursive = recursive;

                                    // do not load recursive if there is potential circular dependency
                                    if (entryList.Contains(row.Code))
                                    {
                                        loadRecursive = false;
                                    }

                                    Entry childEntry = LoadEntry(childRow, loadRecursive, responseGroup, ref entryList);
                                    childEntry.ParentEntry = null;
                                    entryAssociation.Entry = childEntry;

                                    entryAssociationList.Add(entryAssociation);
                                }

                                association.EntryAssociations             = new EntryAssociations();
                                association.EntryAssociations.Association = entryAssociationList.ToArray();
                            }
                        }
                    }
                }

                // Populate children
                if (recursive && (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Children)))
                {
                    bool loadRecursive = recursive;

                    // do not load recursive if there is potential circular dependency
                    if (entryList.Contains(row.Code))
                    {
                        loadRecursive = false;
                    }

                    CatalogEntryDto childrenDto = GetCatalogEntriesDto(row.CatalogEntryId, String.Empty, String.Empty, responseGroup);
                    Entries         entries     = LoadEntries(childrenDto, entry, loadRecursive, responseGroup, ref entryList);
                    entry.Entries = entries;
                }
            }

            /*
             * else
             *  entry = new Entry();
             * */

            return(entry);
        }
예제 #19
0
        private void BindDataType()
        {
            DataRow   dr;
            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("key", typeof(string)));
            dt.Columns.Add(new DataColumn("name", typeof(string)));
            dt.Columns.Add(new DataColumn("Type", typeof(string)));
            dt.Columns.Add(new DataColumn("IsSystemDictionary", typeof(bool)));
            dt.Columns.Add(new DataColumn("AllowNulls", typeof(bool)));
            dt.Columns.Add(new DataColumn("IsConstant", typeof(bool)));

            MappingMetaClass mmc = null;

            MetaDataPlus.Import.Rule mapping = null;
            string MetaClassName             = ddlMetaClass.SelectedValue;
            string language = ddlLanguage.SelectedValue;

            switch (ddlTypeData.SelectedValue)
            {
            case "Category":
                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                CatalogContext.MetaDataContext.Language            = language;

                if (!String.IsNullOrEmpty(MetaClassName))
                {
                    mmc = new CategoryMappingMetaClass(CatalogContext.MetaDataContext, MetaClassName, -1);
                }
                else
                {
                    mmc = new CategoryMappingMetaClass(CatalogContext.MetaDataContext, -1);
                }

                CatalogContext.MetaDataContext.UseCurrentUICulture = true;

                mapping = mmc.CreateClassRule();
                mapping.Attribute.Add("TypeName", "Category");

                if (!String.IsNullOrEmpty(language))
                {
                    mapping.Attribute.Add("Language", language);
                }
                break;

            case "Entry":
                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                CatalogContext.MetaDataContext.Language            = language;

                if (!String.IsNullOrEmpty(MetaClassName))
                {
                    mmc = new EntryMappingMetaClass(CatalogContext.MetaDataContext, MetaClassName, -1);
                }
                else
                {
                    mmc = new EntryMappingMetaClass(CatalogContext.MetaDataContext, -1);
                }

                CatalogContext.MetaDataContext.UseCurrentUICulture = true;

                mapping = mmc.CreateClassRule();
                mapping.Attribute.Add("TypeName", "Entry");

                if (!String.IsNullOrEmpty(language))
                {
                    mapping.Attribute.Add("Language", language);
                }
                break;

            case "EntryRelation":
                mmc     = new EntryRelationMappingMetaClass(CatalogContext.MetaDataContext, -1);
                mapping = mmc.CreateClassRule();
                mapping.Attribute.Add("TypeName", "EntryRelation");
                break;

            case "EntryAssociation":
                mmc     = new EntryAssociationMappingMetaClass(CatalogContext.MetaDataContext, -1);
                mapping = mmc.CreateClassRule();
                mapping.Attribute.Add("TypeName", "EntryAssociation");
                break;

            case "Variation":
                mmc     = new VariationMappingMetaClass(CatalogContext.MetaDataContext, -1);
                mapping = mmc.CreateClassRule();
                mapping.Attribute.Add("TypeName", "Variation");
                break;

            case "SalePrice":
                mmc     = new PricingMappingMetaClass(CatalogContext.MetaDataContext, -1);
                mapping = mmc.CreateClassRule();
                mapping.Attribute.Add("TypeName", "SalePrice");
                break;

            default:
                return;
            }
            mapping.Attribute.Add("Delimiter", this.ddlDelimiter.SelectedValue);
            mapping.Attribute.Add("TextQualifier", this.ddlTextQualifier.SelectedValue);
            foreach (ColumnInfo ci in mmc.ColumnInfos)
            {
                dr = dt.NewRow();
                if (ci.Field.IsSystem)
                {
                    dr["key"]  = ci.FieldName;
                    dr["name"] = (ci.FieldFriendlyName != null) ? ci.FieldFriendlyName : ci.FieldName;
                }
                else
                {
                    dr["key"]  = ci.FieldName;
                    dr["name"] = ci.FieldFriendlyName;
                }

                if (ci.Field.MultiLanguageValue && !String.IsNullOrEmpty(language))
                {
                    dr["name"] += String.Format(" ({0})", language);
                }

                dr["Type"] = ci.Field.DataType.ToString();
                dr["IsSystemDictionary"] = ci.IsSystemDictionary;
                dr["AllowNulls"]         = ci.Field.AllowNulls;
                dr["IsConstant"]         = false;
                dt.Rows.Add(dr);
                mapping.Add(new RuleItem(ci.Field, MetaDataPlus.Import.FillType.NotUse));
            }
            grdFields.Columns[0].HeaderText = RM.GetString("IMPORT_MAPPING_TITLE_FIELDS");
            grdFields.Columns[1].HeaderText = RM.GetString("IMPORT_MAPPING_TITLE_COLUMN_HEADERS");
            grdFields.Columns[2].HeaderText = "Custom values";
            grdFields.DataSource            = dt;
            grdFields.DataBind();
            this.ClassRule = mapping;

            if (ddlDataFiles.SelectedIndex > 0)
            {
                IIncomingDataParser parser  = null;
                DataSet             rawData = null;
                try
                {
                    char chTextQualifier = (this.ddlTextQualifier.SelectedValue == "") ? '\0' : char.Parse(this.ddlTextQualifier.SelectedValue);
                    parser  = new CsvIncomingDataParser(SourcePath, true, char.Parse(this.ddlDelimiter.SelectedValue), chTextQualifier, true, GetEncoding(this.ddlEncoding.SelectedValue));
                    rawData = parser.Parse(ddlDataFiles.SelectedItem.Text, null);
                }
                catch (Exception ex)
                {
                    DisplayErrorMessage(ex.Message);
                    return;
                }
                DataTable dtSource = rawData.Tables[0];

                DataTable dtColumns = new DataTable();
                dtColumns.Columns.Add(new DataColumn("Text", typeof(string)));
                dtColumns.Columns.Add(new DataColumn("Value", typeof(string)));

                foreach (DataColumn dc in dtSource.Columns)
                {
                    dr          = dtColumns.NewRow();
                    dr["Text"]  = "Column " + (dc.Ordinal + 1) + " - " + dc.ColumnName;
                    dr["Value"] = dc.ColumnName;
                    dtColumns.Rows.Add(dr);
                }

                foreach (DataGridItem dgi in grdFields.Items)
                {
                    DropDownList ddl           = (DropDownList)dgi.FindControl("ddlFields");
                    TextBox      tbCustomValue = (TextBox)dgi.FindControl("tbCustomValue");
                    DropDownList ddlValues     = (DropDownList)dgi.FindControl("ddlValues");

                    string sKey  = dgi.Cells[3].Text;
                    string sType = dgi.Cells[4].Text;
                    bool   sIsSystemDictionary = bool.Parse(dgi.Cells[5].Text);
                    bool   allowNulls          = bool.Parse(dgi.Cells[6].Text);
                    bool   IsConstant          = bool.Parse(dgi.Cells[7].Text);

                    bool useDictionaryControl = GetUseDictionaryFlag(dgi);

                    if (!IsConstant)
                    {
                        if (ddl != null)
                        {
                            ddl.DataSource     = dtColumns;
                            ddl.DataTextField  = "Text";
                            ddl.DataValueField = "Value";
                            ddl.DataBind();

                            if (sIsSystemDictionary)
                            {
                                ddl.Items.Insert(0, new ListItem("<" + RM.GetString("IMPORT_TYPE_VALUES_DICTIONARY_VALUE") + ">", "CustomValue"));
                            }
                            else
                            {
                                ddl.Items.Insert(0, new ListItem("<" + RM.GetString("IMPORT_TYPE_VALUES_CUSTOM_VALUE") + ">", "CustomValue"));
                            }

                            if (allowNulls)
                            {
                                ddl.Items.Insert(0, new ListItem("", ""));
                            }
                            else
                            {
                                ddl.Items.Insert(0, new ListItem("<" + RM.GetString("IMPORT_TYPE_VALUES_NOT_SET") + ">", "NotSet"));
                            }

                            string customControlID = useDictionaryControl ? ddlValues.ClientID : tbCustomValue.ClientID;

                            string jsDllOnChange = String.Format("ddlOnChange(this, 'CustomValue', '{0}')", customControlID);
                            ddl.Attributes.Add("OnChange", jsDllOnChange);
                        }
                    }

                    //fill custom or dictionary controls
                    ddlValues.Visible     = useDictionaryControl;
                    tbCustomValue.Visible = !ddlValues.Visible;

                    if (sType.Equals(MetaDataType.Boolean.ToString()) || sType.Equals(MetaDataType.Bit.ToString()))
                    {
                        ddlValues.Items.Clear();
                        ddlValues.Items.Add("True");
                        ddlValues.Items.Add("False");
                    }

                    if (sKey.Equals("sys_RowAction"))
                    {
                        ddlValues.Items.Clear();
                        ddlValues.Items.Add(RowAction.Default.ToString());
                        ddlValues.Items.Add(RowAction.Insert.ToString());
                        ddlValues.Items.Add(RowAction.Update.ToString());
                        ddlValues.Items.Add(RowAction.Delete.ToString());
                    }

                    switch (ddlTypeData.SelectedValue)
                    {
                    case "Category":
                        if (sKey == "TemplateName")
                        {
                            TemplateDto templates = DictionaryManager.GetTemplateDto();
                            if (templates.main_Templates.Count > 0)
                            {
                                DataView view = templates.main_Templates.DefaultView;
                                view.RowFilter           = "TemplateType = 'node'";
                                ddlValues.DataTextField  = "FriendlyName";
                                ddlValues.DataValueField = "Name";
                                ddlValues.DataSource     = view;
                                ddlValues.DataBind();
                            }
                        }
                        break;

                    case "Entry":
                        if (sKey == "ClassTypeId")
                        {
                            ddlValues.Items.Clear();
                            ddlValues.Items.Add(new ListItem("Product", EntryType.Product));
                            ddlValues.Items.Add(new ListItem("Variation/Sku", EntryType.Variation));
                            ddlValues.Items.Add(new ListItem("Package", EntryType.Package));
                            ddlValues.Items.Add(new ListItem("Bundle", EntryType.Bundle));
                            ddlValues.Items.Add(new ListItem("Dynamic Package", EntryType.DynamicPackage));
                        }

                        if (sKey == "TemplateName")
                        {
                            TemplateDto templates = DictionaryManager.GetTemplateDto();
                            if (templates.main_Templates.Count > 0)
                            {
                                DataView view = templates.main_Templates.DefaultView;
                                view.RowFilter           = "TemplateType = 'entry'";
                                ddlValues.DataTextField  = "FriendlyName";
                                ddlValues.DataValueField = "Name";
                                ddlValues.DataSource     = view;
                                ddlValues.DataBind();
                            }
                        }
                        break;

                    case "EntryAssociation":
                        if (sKey == "AssociationType")
                        {
                            ddlValues.Items.Clear();
                            CatalogAssociationDto dto = CatalogContext.Current.GetCatalogAssociationDto(0);
                            if (dto.AssociationType.Count > 0)
                            {
                                ddlValues.DataTextField  = "Description";
                                ddlValues.DataValueField = "AssociationTypeId";
                                ddlValues.DataSource     = dto.AssociationType;
                                ddlValues.DataBind();
                            }
                        }
                        break;

                    case "Variation":
                        if (sKey == "TaxCategoryId")
                        {
                            CatalogTaxDto taxes = CatalogTaxManager.GetTaxCategories();
                            if (taxes.TaxCategory != null)
                            {
                                ddlValues.DataTextField  = "Name";
                                ddlValues.DataValueField = "TaxCategoryId";
                                ddlValues.DataSource     = taxes.TaxCategory.Rows;
                                ddlValues.DataBind();
                            }
                        }
                        if (sKey == "MerchantId")
                        {
                            CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto();
                            if (merchants.Merchant != null)
                            {
                                ddlValues.DataTextField  = "Name";
                                ddlValues.DataValueField = "MerchantId";
                                ddlValues.DataSource     = merchants.Merchant.Rows;
                                ddlValues.DataBind();
                            }
                        }
                        if (sKey == "WarehouseId")
                        {
                            WarehouseDto warehouses = WarehouseManager.GetWarehouseDto();
                            if (warehouses.Warehouse != null)
                            {
                                ddlValues.DataTextField  = "Name";
                                ddlValues.DataValueField = "WarehouseId";
                                ddlValues.DataSource     = warehouses.Warehouse.Rows;
                                ddlValues.DataBind();
                            }
                        }
                        if (sKey == "PackageId")
                        {
                            ShippingMethodDto shippingDto = ShippingManager.GetShippingPackages();
                            if (shippingDto.Package != null)
                            {
                                ddlValues.DataTextField  = "Name";
                                ddlValues.DataValueField = "PackageId";
                                ddlValues.DataSource     = shippingDto.Package.Rows;
                                ddlValues.DataBind();
                            }
                        }

                        break;

                    case "SalePrice":
                        if (sKey == "SaleType")
                        {
                            ddlValues.Items.Clear();
                            foreach (SalePriceTypeDefinition element in CatalogConfiguration.Instance.SalePriceTypes)
                            {
                                ListItem li = new ListItem(UtilHelper.GetResFileString(element.Description), element.Value.ToString());
                                ddlValues.Items.Add(li);
                            }
                        }
                        if (sKey == "Currency")
                        {
                            CurrencyDto dto = CatalogContext.Current.GetCurrencyDto();
                            ddlValues.DataTextField  = "Name";
                            ddlValues.DataValueField = "CurrencyCode";
                            ddlValues.DataSource     = dto.Currency;
                            ddlValues.DataBind();
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CatalogAssociationAdmin"/> class.
 /// </summary>
 /// <param name="dto">The dto.</param>
 internal CatalogAssociationAdmin(CatalogAssociationDto dto)
 {
     _DataSet = dto;
 }
예제 #21
0
 /// <summary>
 /// Loads the context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void LoadContext(IDictionary context)
 {
     _CatalogAssociationDto = (CatalogAssociationDto)context[_CatalogAssociationDtoString];
     EntryAssociationEditDialog.LoadContext(context);
 }
예제 #22
0
 /// <summary>
 /// Saves the catalog association.
 /// </summary>
 /// <param name="dto">The dto.</param>
 public void SaveCatalogAssociation(CatalogAssociationDto dto)
 {
     CatalogAssociationManager.SaveCatalogAssociation(dto);
 }
예제 #23
0
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction    = Item[i++];
            object objAssociationName = Item[i++];
            object objParentCode      = Item[i++];
            object objChildCode       = Item[i++];
            object objSortOrder       = Item[i++];
            object objAssociationType = Item[i++];

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string AssociationName;
                if (!String.IsNullOrEmpty((string)objAssociationName))
                {
                    AssociationName = (string)objAssociationName;
                }
                else
                {
                    throw new AbsentValue("Association Name");
                }

                string parentCode;
                if (!String.IsNullOrEmpty((string)objParentCode))
                {
                    parentCode = (string)objParentCode;
                }
                else
                {
                    throw new AbsentValue("Parent Entry Code");
                }

                string childCode;
                if (!String.IsNullOrEmpty((string)objChildCode))
                {
                    childCode = (string)objChildCode;
                }
                else
                {
                    throw new AbsentValue("Child Entry Code");
                }

                bool bIsNew = false;

                //Parent Entry
                CatalogEntryDto.CatalogEntryRow parentEntryRow = null;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(parentCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Associations));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    parentEntryRow = catalogEntryDto.CatalogEntry[0];
                }
                else
                {
                    throw new MDPImportException(String.Format("The Parent Entry with code '{0}' does not exists.", parentCode));
                }

                //Child Entry
                CatalogEntryDto.CatalogEntryRow childEntryRow = null;
                CatalogEntryDto childEntryDto = CatalogEntryManager.GetCatalogEntryDto(childCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                if (childEntryDto.CatalogEntry.Count > 0)
                {
                    childEntryRow = childEntryDto.CatalogEntry[0];
                }
                else
                {
                    throw new MDPImportException(String.Format("The Child Entry with code '{0}' does not exists.", childCode));
                }

                //CatalogAssociation (define CatalogAssociationId)
                int catalogAssociationId = 0;
                CatalogEntryDto.CatalogAssociationRow[] catalogAssociationRows = (CatalogEntryDto.CatalogAssociationRow[])catalogEntryDto.CatalogAssociation.Select(String.Format("AssociationName = '{0}'", AssociationName));
                if (catalogAssociationRows.Length == 0)
                {
                    CatalogEntryDto.CatalogAssociationRow newCatalogAssociationRow = catalogEntryDto.CatalogAssociation.NewCatalogAssociationRow();
                    newCatalogAssociationRow.CatalogEntryId         = parentEntryRow.CatalogEntryId;
                    newCatalogAssociationRow.AssociationName        = AssociationName;
                    newCatalogAssociationRow.AssociationDescription = String.Empty;
                    newCatalogAssociationRow.SortOrder = 0;
                    catalogEntryDto.CatalogAssociation.AddCatalogAssociationRow(newCatalogAssociationRow);

                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);

                    catalogAssociationId = newCatalogAssociationRow.CatalogAssociationId;
                }
                else
                {
                    catalogAssociationId = catalogAssociationRows[0].CatalogAssociationId;
                }

                //catalogEntryAssociationRow
                CatalogAssociationDto catalogAssociationDto = CatalogAssociationManager.GetCatalogAssociationDto(catalogAssociationId);
                CatalogAssociationDto.CatalogAssociationRow catalogAssociationRow = catalogAssociationDto.CatalogAssociation[0];

                CatalogAssociationDto.CatalogEntryAssociationRow catalogEntryAssociationRow = null;

                CatalogAssociationDto.CatalogEntryAssociationRow[] catalogEntryAssociationRows = (CatalogAssociationDto.CatalogEntryAssociationRow[])catalogAssociationDto.CatalogEntryAssociation.Select(String.Format("CatalogEntryId = {0}", childEntryRow.CatalogEntryId));
                if (catalogEntryAssociationRows.Length == 0)
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode));
                    }

                    if (sysRowAction == RowAction.Delete)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode));
                    }

                    catalogEntryAssociationRow = catalogAssociationDto.CatalogEntryAssociation.NewCatalogEntryAssociationRow();
                    catalogEntryAssociationRow.CatalogAssociationId = catalogAssociationId;
                    catalogEntryAssociationRow.CatalogEntryId       = childEntryRow.CatalogEntryId;
                    catalogEntryAssociationRow.SortOrder            = 0;
                    if (catalogAssociationDto.AssociationType.Count > 0)
                    {
                        catalogEntryAssociationRow.AssociationTypeId = catalogAssociationDto.AssociationType[0].AssociationTypeId;
                    }

                    bIsNew = true;
                }
                else
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' already exists.", AssociationName, parentCode, childCode));
                    }

                    catalogEntryAssociationRow = catalogEntryAssociationRows[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        catalogEntryAssociationRow.Delete();
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                        return(0);
                    }
                }

                if (objSortOrder != null)
                {
                    catalogEntryAssociationRow.SortOrder = (int)objSortOrder;
                }

                if (objAssociationType != null)
                {
                    string associationType = (string)objAssociationType;
                    if (!catalogEntryAssociationRow.AssociationTypeId.Equals(associationType))
                    {
                        CatalogAssociationDto.AssociationTypeRow[] associationTypeRows = (CatalogAssociationDto.AssociationTypeRow[])catalogAssociationDto.AssociationType.Select(String.Format("AssociationTypeId = '{0}'", associationType));
                        if (associationTypeRows.Length > 0)
                        {
                            catalogEntryAssociationRow.AssociationTypeId = associationTypeRows[0].AssociationTypeId;
                        }
                    }
                }

                if (bIsNew)
                {
                    catalogAssociationDto.CatalogEntryAssociation.AddCatalogEntryAssociationRow(catalogEntryAssociationRow);
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogAssociationDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(1);
        }
예제 #24
0
 /// <summary>
 /// Saves the catalog association.
 /// </summary>
 /// <param name="dto">The dto.</param>
 public void SaveCatalogAssociation(CatalogAssociationDto dto)
 {
     _Proxy.SaveCatalogAssociation(dto);
 }
예제 #25
0
        /// <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)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            CatalogEntryDto       dto         = null;
            CatalogRelationDto    relation    = null;
            CatalogAssociationDto association = null;

            using (TransactionScope scope = new TransactionScope())
            {
                if (CatalogEntryId > 0)
                {
                    dto         = (CatalogEntryDto)Session[_CatalogEntryDtoString];
                    relation    = (CatalogRelationDto)Session[_CatalogRelationDtoString];
                    association = (CatalogAssociationDto)Session[_CatalogAssociationDtoString];
                }

                if (association == null && CatalogEntryId > 0)
                {
                    association = LoadAssociation();
                }

                if (relation == null && CatalogEntryId > 0)
                {
                    relation = LoadRelation();
                }

                if (dto == null && CatalogEntryId > 0)
                {
                    dto = LoadEntry();
                }

                CreateEmptyDtos(ref dto, ref relation, ref association, true);

                // Put a dictionary key that can be used by other tabs
                IDictionary dic = new ListDictionary();
                dic.Add(_CatalogEntryDtoString, dto);
                dic.Add(_CatalogRelationDtoString, relation);
                dic.Add(_CatalogAssociationDtoString, association);

                // Call tabs save
                ViewControl.SaveChanges(dic);

                // Save modifications
                if (dto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogEntry(dto);
                }

                // get current CatalogEntryId
                int currentCatalogEntryId = this.CatalogEntryId;
                if (dto.CatalogEntry != null && dto.CatalogEntry.Rows.Count > 0)
                {
                    currentCatalogEntryId = dto.CatalogEntry[0].CatalogEntryId;
                }

                // Modify relationship
                CatalogRelationDto.NodeEntryRelationRow relRow = null;

                // Find existing row
                if (relation.NodeEntryRelation.Count > 0)
                {
                    foreach (CatalogRelationDto.NodeEntryRelationRow row in relation.NodeEntryRelation.Rows)
                    {
                        if (row.CatalogEntryId == currentCatalogEntryId && row.CatalogId == ParentCatalogId && row.CatalogNodeId == ParentCatalogNodeId)
                        {
                            relRow = row;
                            break;
                        }
                    }
                }

                // If no existing record found, create a new one
                if (ParentCatalogId > 0 && ParentCatalogNodeId > 0)
                {
                    if (relRow == null)
                    {
                        relRow = relation.NodeEntryRelation.NewNodeEntryRelationRow();
                    }

                    if (ParentCatalogId > 0)
                    {
                        relRow.CatalogId = ParentCatalogId;
                    }

                    if (this.ParentCatalogNodeId > 0)
                    {
                        relRow.CatalogNodeId = this.ParentCatalogNodeId;
                    }

                    relRow.CatalogEntryId = currentCatalogEntryId;

                    // Attach if it is a new row
                    if (relRow.RowState == DataRowState.Detached)
                    {
                        relRow.SortOrder = 0;
                        relation.NodeEntryRelation.Rows.Add(relRow);
                    }
                }

                // Update newly added entry relationships with a parent catalog entry id
                if (relation.CatalogEntryRelation.Rows.Count > 0)
                {
                    foreach (CatalogRelationDto.CatalogEntryRelationRow row in relation.CatalogEntryRelation.Rows)
                    {
                        if (row.RowState == DataRowState.Added && row.ParentEntryId <= 0)
                        {
                            row.ParentEntryId = currentCatalogEntryId;
                        }
                    }
                }

                if (relation.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(relation);
                }

                // Update newly added entry relationships with a parent catalog entry id
                if (association.CatalogAssociation.Rows.Count > 0)
                {
                    foreach (CatalogAssociationDto.CatalogAssociationRow row in association.CatalogAssociation.Rows)
                    {
                        if (row.RowState == DataRowState.Added && row.CatalogEntryId <= 0)
                        {
                            row.CatalogEntryId = currentCatalogEntryId;
                        }
                    }
                }

                // Save association modifications
                if (association.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogAssociation(association);
                }

                // Call commit changes
                ViewControl.CommitChanges(dic);

                // Save modifications
                if (dto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogEntry(dto);
                }

                // Save relation modifications
                if (relation.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(relation);
                }

                // Save association modifications
                if (association.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogAssociation(association);
                }

                // Complete transaction
                scope.Complete();

                // we don't need to store Dto in session any more
                Session.Remove(_CatalogEntryDtoString);
                Session.Remove(_CatalogRelationDtoString);
                Session.Remove(_CatalogAssociationDtoString);
            }
        }
예제 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CatalogAssociationAdmin"/> class.
 /// </summary>
 internal CatalogAssociationAdmin()
 {
     _DataSet = new CatalogAssociationDto();
 }
예제 #27
0
        /// <summary>
        /// Clones the node entry.
        /// </summary>
        /// <param name="catalogId">The catalog id.</param>
        /// <param name="catalogNodeId">The catalog node id.</param>
        /// <param name="catalogEntryId">The catalog entry id.</param>
        /// <param name="targetCatalogId">The target catalog id.</param>
        /// <param name="targetCatalogNodeId">The target catalog node id.</param>
        private void CloneNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    if (catalogId <= 0)
                    {
                        catalogId = catalogEntryDto.CatalogEntry[0].CatalogId;
                    }

                    if (targetCatalogId <= 0)
                    {
                        targetCatalogId = catalogId;
                    }

                    CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));

                    CatalogAssociationDto catalogAssociationDto = CatalogContext.Current.GetCatalogAssociationDtoByEntryId(catalogEntryId);

                    CatalogEntryDto newCatalogEntryDto = new CatalogEntryDto();
                    newCatalogEntryDto.CatalogEntry.ImportRow(catalogEntryDto.CatalogEntry[0]);
                    newCatalogEntryDto.CatalogEntry[0].SetAdded();
                    newCatalogEntryDto.CatalogEntry[0].Code = Guid.NewGuid().ToString();

                    if (catalogEntryDto.CatalogItemSeo.Count > 0)
                    {
                        foreach (CatalogEntryDto.CatalogItemSeoRow row in catalogEntryDto.CatalogItemSeo.Rows)
                        {
                            newCatalogEntryDto.CatalogItemSeo.ImportRow(row);
                            newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].SetAdded();
                            newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx";
                        }
                    }

                    if (catalogEntryDto.Variation.Count > 0)
                    {
                        foreach (CatalogEntryDto.VariationRow row in catalogEntryDto.Variation.Rows)
                        {
                            newCatalogEntryDto.Variation.ImportRow(row);
                            newCatalogEntryDto.Variation[newCatalogEntryDto.Variation.Count - 1].SetAdded();
                        }
                    }

                    if (catalogEntryDto.SalePrice.Count > 0)
                    {
                        foreach (CatalogEntryDto.SalePriceRow row in catalogEntryDto.SalePrice.Rows)
                        {
                            CatalogEntryDto.SalePriceRow newRow = newCatalogEntryDto.SalePrice.NewSalePriceRow();
                            newRow.ItemArray = row.ItemArray;
                            newRow.ItemCode  = newCatalogEntryDto.CatalogEntry[0].Code;
                            newCatalogEntryDto.SalePrice.Rows.Add(newRow);
                            //newCatalogEntryDto.SalePrice.ImportRow(row);
                            //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].ItemCode = newCatalogEntryDto.CatalogEntry[0].Code;
                            //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].SetAdded();
                        }
                    }

                    if (catalogEntryDto.Inventory.Count > 0)
                    {
                        foreach (CatalogEntryDto.InventoryRow row in catalogEntryDto.Inventory.Rows)
                        {
                            newCatalogEntryDto.Inventory.ImportRow(row);
                            newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SetAdded();
                            newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SkuId = newCatalogEntryDto.CatalogEntry[0].Code;
                        }
                    }

                    if (newCatalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(newCatalogEntryDto);
                    }

                    if (newCatalogEntryDto.CatalogEntry.Count > 0)
                    {
                        CatalogEntryDto.CatalogEntryRow entry = newCatalogEntryDto.CatalogEntry[0];
                        int newCatalogEntryId = entry.CatalogEntryId;
                        int metaClassId       = entry.MetaClassId;

                        // load list of MetaFields for MetaClass
                        MetaClass           metaClass  = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId);
                        MetaFieldCollection metaFields = metaClass.MetaFields;

                        // cycle through each language and get meta objects
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                        string[] languages = GetCatalogLanguages(catalogId);
                        if (languages != null)
                        {
                            foreach (string language in languages)
                            {
                                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                                CatalogContext.MetaDataContext.Language            = language;

                                MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogEntryDto.CatalogEntry[0].CatalogEntryId, metaClassId);

                                MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogEntryId, metaClassId, FrameworkContext.Current.Profile.UserName);

                                foreach (MetaField metaField in metaFields)
                                {
                                    // skip system MetaFields
                                    if (!metaField.IsUser)
                                    {
                                        continue;
                                    }

                                    switch (metaField.DataType)
                                    {
                                    case MetaDataType.File:
                                    case MetaDataType.Image:
                                    case MetaDataType.ImageFile:
                                        MetaFile metaFile = (MetaFile)metaObject[metaField];
                                        if (metaFile != null)
                                        {
                                            newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer);
                                        }
                                        break;

                                    default:
                                        if (metaObject[metaField] != null)
                                        {
                                            newMetaObject[metaField] = metaObject[metaField];
                                        }
                                        break;
                                    }
                                }
                                newMetaObject.AcceptChanges(CatalogContext.MetaDataContext);
                            }
                        }
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;

                        CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto();

                        foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows)
                        {
                            if (row.ParentEntryId == catalogEntryId)
                            {
                                newCatalogRelationDto.CatalogEntryRelation.ImportRow(row);
                                newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].SetAdded();
                                newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].ParentEntryId = newCatalogEntryId;
                            }
                        }

                        if (targetCatalogNodeId > 0)
                        {
                            foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                            {
                                if (row.CatalogEntryId == catalogEntryId)
                                {
                                    newCatalogRelationDto.NodeEntryRelation.ImportRow(row);
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].SetAdded();
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogId      = targetCatalogId;
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogNodeId  = targetCatalogNodeId;
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogEntryId = newCatalogEntryId;
                                }
                            }
                        }

                        if (newCatalogRelationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto);
                        }

                        CatalogAssociationDto newCatalogAssociationDto = new CatalogAssociationDto();

                        foreach (CatalogAssociationDto.CatalogAssociationRow row in catalogAssociationDto.CatalogAssociation.Rows)
                        {
                            newCatalogAssociationDto.CatalogAssociation.ImportRow(row);
                            newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].SetAdded();
                            newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].CatalogEntryId = newCatalogEntryId;
                        }

                        foreach (CatalogAssociationDto.CatalogEntryAssociationRow row in catalogAssociationDto.CatalogEntryAssociation.Rows)
                        {
                            newCatalogAssociationDto.CatalogEntryAssociation.ImportRow(row);
                            newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].SetAdded();
                            //newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].CatalogEntryId = newCatalogEntryId;
                        }

                        if (newCatalogAssociationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogAssociation(newCatalogAssociationDto);
                        }
                    }
                }

                scope.Complete();
            }
        }
예제 #28
0
        /// <summary>
        /// Deletes the entry recursive.
        /// </summary>
        /// <param name="entryId">The entry id.</param>
        /// <param name="parentCatalogId">The parent catalog id.</param>
        /// <param name="parentCatalogNodeId">The parent catalog node id.</param>
        private void DeleteEntryRecursive(int entryId, int parentCatalogId, int parentCatalogNodeId)
        {
            CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            if (catalogEntryDto.CatalogEntry.Count > 0)
            {
                bool deleteEntry = true;                 // flag which will determine if we are deleting an entry

                //Delete NodeEntryRelation rows
                CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                int totalRelations = catalogRelationDto.NodeEntryRelation.Count;
                foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                {
                    if (row.CatalogId == parentCatalogId && row.CatalogNodeId == parentCatalogNodeId)
                    {
                        row.Delete();
                        totalRelations--;
                    }
                    else if (parentCatalogId == catalogEntryDto.CatalogEntry[0].CatalogId && parentCatalogNodeId == 0)                     // delete other catalog relationship if we deleting entry in primary catalog the entry belongs to and we deleting from the very root of catalog
                    {
                        row.Delete();
                        totalRelations--;
                    }
                }

                if (catalogRelationDto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);
                }

                // Do not delete if there are more than 1 relationships or if the current catalog is not the primary one
                if (totalRelations > 0 || parentCatalogId != catalogEntryDto.CatalogEntry[0].CatalogId)
                {
                    deleteEntry = false;
                }

                if (deleteEntry)
                {
                    //Delete CatalogEntryAssociation rows
                    foreach (CatalogEntryDto.CatalogAssociationRow catalogAssociationRow in catalogEntryDto.CatalogAssociation)
                    {
                        CatalogAssociationDto catalogAssociationDto = FrameworkContext.Current.CatalogSystem.GetCatalogAssociationDto(catalogAssociationRow.CatalogAssociationId);
                        foreach (CatalogAssociationDto.CatalogEntryAssociationRow itemCatalogEntryAssociation in catalogAssociationDto.CatalogEntryAssociation)
                        {
                            itemCatalogEntryAssociation.Delete();
                        }

                        if (catalogAssociationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                        }
                    }

                    //Delete relations with all sub entries
                    CatalogRelationDto relation = CatalogContext.Current.GetCatalogRelationDto(parentCatalogId, parentCatalogNodeId, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));
                    foreach (CatalogRelationDto.CatalogEntryRelationRow relationRow in relation.CatalogEntryRelation)
                    {
                        relationRow.Delete();
                    }
                    CatalogContext.Current.SaveCatalogRelationDto(relation);

                    CatalogEntryDto.CatalogEntryRow entryRow = catalogEntryDto.CatalogEntry[0];

                    // Delete inventory if on exists
                    if (entryRow.InventoryRow != null)
                    {
                        entryRow.InventoryRow.Delete();
                    }

                    //Delete entry row
                    entryRow.Delete();
                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                }
            }
        }