예제 #1
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);
        }
예제 #2
0
        /// <summary>
        /// Loads the new entry.
        /// </summary>
        /// <returns></returns>
        protected override Entry LoadNewEntry()
        {
            // Load using base implementation
            Entry entry = base.LoadNewEntry();

            // Add additional association to accomodate service plan and demonstrate dynamic products
            List <Association> associationList = new List <Association>();

            Association optionsAssoc = null;

            if (entry.Associations != null)
            {
                foreach (Association assoc in entry.Associations)
                {
                    if (assoc.Name.Equals("AdditionalOptions", StringComparison.OrdinalIgnoreCase))
                    {
                        optionsAssoc = assoc;
                    }

                    associationList.Add(assoc);
                }
            }

            if (optionsAssoc == null)
            {
                optionsAssoc             = new Association();
                optionsAssoc.Name        = "AdditionalOptions";
                optionsAssoc.Description = "Additional Options";
                associationList.Add(optionsAssoc);
            }

            List <EntryAssociation> entryAssociationList = new List <EntryAssociation>();

            if (optionsAssoc.EntryAssociations == null)
            {
                optionsAssoc.EntryAssociations = new EntryAssociations();
            }

            if (optionsAssoc.EntryAssociations.Association != null)
            {
                foreach (EntryAssociation assoc in optionsAssoc.EntryAssociations.Association)
                {
                    entryAssociationList.Add(assoc);
                }
            }

            // Add new association and made up entry
            Entry newEntry = new Entry();

            newEntry.ID                         = "@2YEARSERVICEPLAN-" + entry.ID;
            newEntry.Name                       = "2 Years Service Plan";
            newEntry.ItemAttributes             = new ItemAttributes();
            newEntry.ItemAttributes.MinQuantity = 1;
            newEntry.ItemAttributes.MaxQuantity = 1;
            newEntry.ParentEntry                = entry;

            Price listPrice = StoreHelper.GetSalePrice(entry, 1);

            newEntry.ItemAttributes.ListPrice = ObjectHelper.CreatePrice(decimal.Multiply(listPrice.Amount, (decimal)0.10), listPrice.CurrencyCode);

            EntryAssociation newAssociation = new EntryAssociation();

            newAssociation.AssociationType = "OPTIONAL";
            newAssociation.SortOrder       = 0;
            newAssociation.AssociationDesc = "";
            newAssociation.Entry           = newEntry;
            entryAssociationList.Add(newAssociation);

            optionsAssoc.EntryAssociations.Association = entryAssociationList.ToArray();
            entry.Associations = associationList.ToArray();

            return(entry);
        }