예제 #1
0
 /// <summary>
 /// Gets the catalog node dto.
 /// </summary>
 /// <param name="uri">The URI.</param>
 /// <param name="languageCode">The language code.</param>
 /// <returns></returns>
 public CatalogNodeDto GetCatalogNodeDto(string uri, string languageCode)
 {
     return(CatalogNodeManager.GetCatalogNodeDto(uri, languageCode, new CatalogNodeResponseGroup()));
 }
예제 #2
0
 /// <summary>
 /// Gets the catalog node dto.
 /// </summary>
 /// <param name="code">The code.</param>
 /// <returns></returns>
 public CatalogNodeDto GetCatalogNodeDto(string code)
 {
     return(CatalogNodeManager.GetCatalogNodeDto(code, new CatalogNodeResponseGroup()));
 }
예제 #3
0
 /// <summary>
 /// Gets the catalog node dto.
 /// </summary>
 /// <param name="code">The code.</param>
 /// <param name="responseGroup">The response group.</param>
 /// <returns></returns>
 public CatalogNodeDto GetCatalogNodeDto(string code, CatalogNodeResponseGroup responseGroup)
 {
     return(CatalogNodeManager.GetCatalogNodeDto(code, responseGroup));
 }
예제 #4
0
 /// <summary>
 /// Gets the catalog node dto.
 /// </summary>
 /// <param name="catalogNodeId">The catalog node id.</param>
 /// <returns></returns>
 public CatalogNodeDto GetCatalogNodeDto(int catalogNodeId)
 {
     return(CatalogNodeManager.GetCatalogNodeDto(catalogNodeId, new CatalogNodeResponseGroup()));
 }
예제 #5
0
 /// <summary>
 /// Gets the catalog node dto.
 /// </summary>
 /// <param name="catalogNodeId">The catalog node id.</param>
 /// <param name="responseGroup">The response group.</param>
 /// <returns></returns>
 public CatalogNodeDto GetCatalogNodeDto(int catalogNodeId, CatalogNodeResponseGroup responseGroup)
 {
     return(CatalogNodeManager.GetCatalogNodeDto(catalogNodeId, responseGroup));
 }
예제 #6
0
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction = Item[i++];
            //CatalogNode
            object objCode         = Item[i++];
            object objParentCode   = Item[i++];
            object objName         = Item[i++];
            object objStartDate    = Item[i++];
            object objEndDate      = Item[i++];
            object objTemplateName = Item[i++];
            object objIsActive     = Item[i++];
            object objSortOrder    = Item[i++];
            //SEO
            object objSeoTitle       = Item[i++];
            object objSeoUrl         = Item[i++];
            object objSeoDescription = Item[i++];
            object objSeoKeywords    = Item[i++];

            CatalogNodeDto.CatalogNodeRow nodeRow = null;

            try
            {
                RowAction sysRowAction = RowAction.Default;

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

                string Code;
                if (!String.IsNullOrEmpty((string)objCode))
                {
                    Code = (string)objCode;
                }
                else
                {
                    throw new AbsentValue("Code");
                }

                int parentNodeId = 0;
                if (objParentCode != null)
                {
                    if (!objParentCode.Equals(String.Empty))
                    {
                        CatalogNodeDto parentNodeDto = CatalogNodeManager.GetCatalogNodeDto((string)objParentCode, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo));
                        if (parentNodeDto.CatalogNode.Count > 0)
                        {
                            parentNodeId = parentNodeDto.CatalogNode[0].CatalogNodeId;
                        }
                    }
                }

                bool           bIsNew         = false;
                CatalogNodeDto catalogNodeDto = CatalogNodeManager.GetCatalogNodeDto(Code, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull));
                if (catalogNodeDto.CatalogNode.Count > 0)
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Catalog Node with Code '{0}' already exists.", Code));
                    }

                    nodeRow = catalogNodeDto.CatalogNode[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        CatalogContext.Current.DeleteCatalogNode(nodeRow.CatalogNodeId, nodeRow.CatalogId);
                        return(0);
                    }

                    if (objParentCode != null && parentNodeId > -1)
                    {
                        nodeRow.ParentNodeId = parentNodeId;
                    }
                }
                else
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Catalog Node with code '{0}' does not exists.", Code));
                    }

                    if (sysRowAction == RowAction.Delete)
                    {
                        throw new MDPImportException(String.Format("The Catalog Node with code '{0}' does not exists.", Code));
                    }

                    nodeRow = catalogNodeDto.CatalogNode.NewCatalogNodeRow();
                    nodeRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId;
                    nodeRow.CatalogId     = _CatalogId;
                    nodeRow.Code          = Code;
                    nodeRow.ParentNodeId  = parentNodeId;
                    nodeRow.Name          = String.Empty;
                    nodeRow.StartDate     = DateTime.UtcNow;
                    nodeRow.EndDate       = DateTime.UtcNow.AddYears(3);
                    nodeRow.TemplateName  = String.Empty;
                    nodeRow.IsActive      = false;
                    nodeRow.SortOrder     = 0;
                    bIsNew = true;
                }

                if (objName != null)
                {
                    nodeRow.Name = (string)objName;
                }

                if (objStartDate != null)
                {
                    nodeRow.StartDate = ((DateTime)objStartDate).ToUniversalTime();
                }

                if (objEndDate != null)
                {
                    nodeRow.EndDate = ((DateTime)objEndDate).ToUniversalTime();
                }

                if (objTemplateName != null)
                {
                    nodeRow.TemplateName = (string)objTemplateName;
                }

                if (objIsActive != null)
                {
                    nodeRow.IsActive = (bool)objIsActive;
                }

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

                int oldMetaClassId = 0;
                if (!_isSystemClass && _metaClassId > 0)
                {
                    if (!bIsNew)
                    {
                        oldMetaClassId = nodeRow.MetaClassId;
                    }

                    nodeRow.MetaClassId = _metaClassId;
                }
                else if (bIsNew)
                {
                    throw new MDPImportException("The new category cannot be created without metaclass definition.");
                }

                if (bIsNew)
                {
                    catalogNodeDto.CatalogNode.AddCatalogNodeRow(nodeRow);
                }

                //SEO
                CatalogNodeDto.CatalogItemSeoRow catalogItemSeoRow = null;
                bool bSeoIsNew = false;
                if (!String.IsNullOrEmpty(this.Context.Language))
                {
                    if (catalogNodeDto.CatalogItemSeo.Count > 0)
                    {
                        DataRow[] drs = catalogNodeDto.CatalogItemSeo.Select(String.Format("LanguageCode LIKE '{0}' AND CatalogNodeId = {1}", this.Context.Language, nodeRow.CatalogNodeId));
                        if (drs.Length > 0)
                        {
                            catalogItemSeoRow = (CatalogNodeDto.CatalogItemSeoRow)drs[0];
                        }
                    }

                    if (catalogItemSeoRow == null)
                    {
                        catalogItemSeoRow = catalogNodeDto.CatalogItemSeo.NewCatalogItemSeoRow();
                        catalogItemSeoRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId;
                        catalogItemSeoRow.LanguageCode  = this.Context.Language.ToLower();
                        catalogItemSeoRow.CatalogNodeId = nodeRow.CatalogNodeId;
                        catalogItemSeoRow.Description   = String.Empty;
                        catalogItemSeoRow.Keywords      = String.Empty;
                        bSeoIsNew = true;
                    }

                    if (objSeoTitle != null)
                    {
                        catalogItemSeoRow.Title = (string)objSeoTitle;
                    }

                    if (objSeoUrl != null)
                    {
                        catalogItemSeoRow.Uri = (string)objSeoUrl;
                    }
                    else if (bSeoIsNew)
                    {
                        // Auto generate the URL if empty
                        string name = catalogNodeDto.CatalogNode[0].Name;
                        string url  = String.Format("{0}.aspx", CommerceHelper.CleanUrlField(name));

                        int index = 1;
                        while (CatalogContext.Current.GetCatalogEntryByUriDto(url, this.Context.Language).CatalogEntry.Count != 0 || CatalogContext.Current.GetCatalogNodeDto(url, this.Context.Language).CatalogNode.Count != 0)
                        {
                            url = String.Format("{0}-{1}.aspx", CommerceHelper.CleanUrlField(name), index.ToString());
                            index++;
                        }

                        catalogItemSeoRow.Uri = url;
                    }


                    if (objSeoDescription != null)
                    {
                        catalogItemSeoRow.Description = (string)objSeoDescription;
                    }

                    if (objSeoKeywords != null)
                    {
                        catalogItemSeoRow.Keywords = (string)objSeoKeywords;
                    }

                    if (bSeoIsNew)
                    {
                        catalogNodeDto.CatalogItemSeo.AddCatalogItemSeoRow(catalogItemSeoRow);
                    }
                }

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

                    if (!bIsNew && !_isSystemClass && oldMetaClassId != nodeRow.MetaClassId)
                    {
                        MetaObject.Delete(this.Context, nodeRow.CatalogNodeId, oldMetaClassId);
                        MetaObject obj = MetaObject.NewObject(this.Context, nodeRow.CatalogNodeId, nodeRow.MetaClassId);
                        obj.AcceptChanges(this.Context);
                    }

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

            return(nodeRow.CatalogNodeId);
        }