Example #1
0
        /// <summary>
        /// Saves the table simple.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="cmd">The CMD.</param>
        /// <param name="table">The table.</param>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        public static DataResult SaveTableSimple(MetaDataContext context, DataCommand cmd, DataTable table, DataViewRowState state)
        {
            cmd.Table    = table;
            cmd.DataRows = table.Select("", "", state);

            // automatically handle deleting meta data related tables
            if (state == DataViewRowState.Deleted)
            {
                if (table.Columns.Contains("MetaClassId"))
                {
                    // Find primary key
                    string primaryKeyColumn = table.PrimaryKey[0].ColumnName;

                    if (cmd.DataRows.Length > 0)
                    {
                        foreach (DataRow row in cmd.DataRows)
                        {
                            MetaObject.Delete(context, Int32.Parse(row[primaryKeyColumn, DataRowVersion.Original].ToString()), Int32.Parse(row["MetaClassId", DataRowVersion.Original].ToString()));
                        }
                    }
                }
            }


            return(DataService.Save(cmd));
        }
Example #2
0
        /// <summary>
        /// Deletes the specified catalog entry id.
        /// </summary>
        /// <param name="catalogEntryId">The catalog entry id.</param>
        internal static void Delete(int catalogEntryId)
        {
            CatalogEntryAdmin admin = new CatalogEntryAdmin();

            admin.Load(catalogEntryId);

            if (admin.CurrentDto.CatalogEntry.Count == 0)
            {
                throw new InvalidObjectException();
            }

            int metaClassId = admin.CurrentDto.CatalogEntry[0].MetaClassId;

            DataCommand cmd = CatalogDataHelper.CreateDataCommand();

            cmd.CommandText = DataHelper.CreateDeleteStoredProcedureName("CatalogEntry");
            cmd.Parameters  = new DataParameters();
            cmd.Parameters.Add(new DataParameter("CatalogEntryId", catalogEntryId));

            using (TransactionScope scop = new TransactionScope())
            {
                DataService.ExecuteNonExec(cmd);
                // Make sure to remove meta data, if any
                if (metaClassId > 0)
                {
                    MetaObject.Delete(CatalogContext.MetaDataContext, catalogEntryId, metaClassId);
                }
            }
        }
Example #3
0
        protected void MainGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentException("e");
            }

            if (e.CommandName == "Delete")
            {
                int        objectId = int.Parse(MainGrid.DataKeys[int.Parse(e.CommandArgument.ToString())].Value.ToString());
                MetaObject mo       = Mediachase.Ibn.Data.Services.Security.GetGlobalAce(mc.Name, objectId);
                mo.Delete();
            }

            CHelper.AddToContext("RebindPage", "true");
        }
Example #4
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            CatalogNodeDto dto = (CatalogNodeDto)context["CatalogNodeDto"];

            CatalogNodeDto.CatalogNodeRow row = null;

            if (dto.CatalogNode == null || dto.CatalogNode.Count == 0)
            {
                row = dto.CatalogNode.NewCatalogNodeRow();
                row.ApplicationId = CatalogConfiguration.Instance.ApplicationId;
            }
            else
            {
                row = dto.CatalogNode[0];
                if (row.MetaClassId != Int32.Parse(MetaClassList.SelectedValue))
                {
                    MetaObject.Delete(CatalogContext.MetaDataContext, row.CatalogNodeId, row.MetaClassId);
                }
            }

            row.Name      = Name.Text;
            row.StartDate = AvailableFrom.Value.ToUniversalTime();
            row.EndDate   = ExpiresOn.Value.ToUniversalTime();
            row.Code      = CodeText.Text;
            row.SortOrder = Int32.Parse(SortOrder.Text);
            row.IsActive  = IsCatalogNodeActive.IsSelected;

            if (ParentCatalogId > 0)
            {
                row.CatalogId = ParentCatalogId;

                if ((ParentCatalogNodeId > 0 && ParentCatalogNodeId != row.CatalogNodeId) || ParentCatalogNodeId == 0)
                {
                    row.ParentNodeId = ParentCatalogNodeId;
                }
            }

            row.TemplateName = DisplayTemplate.SelectedValue;
            row.MetaClassId  = Int32.Parse(MetaClassList.SelectedValue);

            if (row.RowState == DataRowState.Detached)
            {
                dto.CatalogNode.Rows.Add(row);
            }

            dto.CatalogNode.RowChanged += new DataRowChangeEventHandler(CatalogNode_RowChanged);
        }
Example #5
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);
        }
Example #6
0
        protected override int CreateSystemRow(FillDataMode mode, int RowIndex, params object[] item)
        {
            int    i = 0;
            object objSysRowAction = item[i++];
            //Entry
            object objCode          = item[i++];
            object objName          = item[i++];
            object objClassTypeId   = item[i++];
            object objStartDate     = item[i++];
            object objEndDate       = item[i++];
            object objTemplateName  = item[i++];
            object objIsActive      = item[i++];
            object objCategoryCodes = item[i++];
            object objSortOrder     = item[i++];
            //SEO
            object objSeoTitle       = item[i++];
            object objSeoUrl         = item[i++];
            object objSeoDescription = item[i++];
            object objSeoKeywords    = item[i++];

            CatalogEntryDto.CatalogEntryRow entryRow = null;

            try
            {
                RowAction sysRowAction = RowAction.Default;

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

                string code;
                if (objCode != null)
                {
                    code = (string)objCode;
                }
                else
                {
                    throw new AbsentValue("Code");
                }

                bool            bIsNew          = false;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' already exists.", code));
                    }

                    entryRow = catalogEntryDto.CatalogEntry[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        CatalogContext.Current.DeleteCatalogEntry(entryRow.CatalogEntryId, true);
                        return(0);
                    }
                }
                else
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", code));
                    }

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

                    entryRow = catalogEntryDto.CatalogEntry.NewCatalogEntryRow();
                    entryRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId;
                    entryRow.CatalogId     = _CatalogId;
                    entryRow.Code          = code;
                    bIsNew = true;
                }

                //Entry
                if (objName != null)
                {
                    string Name = (string)objName;
                    entryRow.Name = Name;
                }
                else if (bIsNew)
                {
                    throw new AbsentValue("Name");
                }

                if (objClassTypeId != null)
                {
                    string classTypeId = (string)objClassTypeId;
                    entryRow.ClassTypeId = classTypeId;
                }
                else if (bIsNew)
                {
                    entryRow.ClassTypeId = EntryType.Product;
                }

                if (objStartDate != null)
                {
                    DateTime startDate = (DateTime)objStartDate;
                    entryRow.StartDate = startDate.ToUniversalTime();
                }
                else if (bIsNew)
                {
                    entryRow.StartDate = DateTime.UtcNow;
                }

                if (objEndDate != null)
                {
                    DateTime endDate = (DateTime)objEndDate;
                    entryRow.EndDate = endDate.ToUniversalTime();
                }
                else if (bIsNew)
                {
                    entryRow.EndDate = DateTime.UtcNow.AddYears(1);
                }

                if (objTemplateName != null)
                {
                    string templateName = (string)objTemplateName;
                    entryRow.TemplateName = templateName;
                }
                else if (bIsNew)
                {
                    entryRow.TemplateName = String.Empty;
                }

                if (objIsActive != null)
                {
                    bool IsActive = (bool)objIsActive;
                    entryRow.IsActive = IsActive;
                }
                else if (bIsNew)
                {
                    entryRow.IsActive = false;
                }

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

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

                if (bIsNew)
                {
                    catalogEntryDto.CatalogEntry.AddCatalogEntryRow(entryRow);
                }
                else
                {
                    entryRow.SerializedData = null;
                }

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

                    if (catalogItemSeoRow == null)
                    {
                        catalogItemSeoRow = catalogEntryDto.CatalogItemSeo.NewCatalogItemSeoRow();
                        catalogItemSeoRow.ApplicationId  = CatalogConfiguration.Instance.ApplicationId;
                        catalogItemSeoRow.LanguageCode   = this.Context.Language.ToLower();
                        catalogItemSeoRow.CatalogEntryId = entryRow.CatalogEntryId;
                        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 = catalogEntryDto.CatalogEntry.Count > 0 ? catalogEntryDto.CatalogEntry[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)
                    {
                        catalogEntryDto.CatalogItemSeo.AddCatalogItemSeoRow(catalogItemSeoRow);
                    }
                }

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

                    int sortOrder = -1;
                    if (objSortOrder != null)
                    {
                        sortOrder = (int)objSortOrder;
                    }

                    if (objCategoryCodes != null)
                    {
                        //NodeEntryRelation

                        string[] categoryCodes = ((string)objCategoryCodes).Split(',');

                        Catalog.Dto.CatalogRelationDto catalogRelationDto = FrameworkContext.Current.CatalogSystem.GetCatalogRelationDto(this._CatalogId, 0, entryRow.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));

                        Catalog.Dto.CatalogNodeDto catalogNodeDto = FrameworkContext.Current.CatalogSystem.GetCatalogNodesDto(this._CatalogId);
                        if (catalogNodeDto.CatalogNode.Count > 0)
                        {
                            //remove product from category
                            if (catalogRelationDto.NodeEntryRelation.Count > 0)
                            {
                                foreach (CatalogRelationDto.NodeEntryRelationRow nodeEntryRelationRow in catalogRelationDto.NodeEntryRelation)
                                {
                                    DataRow[] catalogNodeDataRows = catalogNodeDto.CatalogNode.Select(String.Format("CatalogNodeId = {0}", nodeEntryRelationRow.CatalogNodeId));
                                    if (catalogNodeDataRows.Length > 0)
                                    {
                                        Catalog.Dto.CatalogNodeDto.CatalogNodeRow catalogNode = (Catalog.Dto.CatalogNodeDto.CatalogNodeRow)catalogNodeDataRows[0];

                                        bool bExist = false;
                                        foreach (string categoryCode in categoryCodes)
                                        {
                                            if (catalogNode.Code.Equals(categoryCode))
                                            {
                                                if (sortOrder >= 0)
                                                {
                                                    nodeEntryRelationRow.SortOrder = sortOrder;
                                                }

                                                bExist = true;
                                                break;
                                            }
                                        }
                                        if (!bExist)
                                        {
                                            nodeEntryRelationRow.Delete();
                                        }
                                    }
                                }
                            }

                            //add entry to category
                            foreach (string categoryCode in categoryCodes)
                            {
                                DataRow[] catalogNodeDataRows = catalogNodeDto.CatalogNode.Select(String.Format("Code = '{0}'", categoryCode.Replace("'", "''")));
                                if (catalogNodeDataRows.Length > 0)
                                {
                                    Catalog.Dto.CatalogNodeDto.CatalogNodeRow catalogNode = (Catalog.Dto.CatalogNodeDto.CatalogNodeRow)catalogNodeDataRows[0];

                                    DataRow[] nodeEntryRelationDataRows = catalogRelationDto.NodeEntryRelation.Select(String.Format("CatalogNodeId = {0}", catalogNode.CatalogNodeId));
                                    if (nodeEntryRelationDataRows.Length == 0)
                                    {
                                        Catalog.Dto.CatalogRelationDto.NodeEntryRelationRow row = catalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow();
                                        row.CatalogId      = this._CatalogId;
                                        row.CatalogEntryId = entryRow.CatalogEntryId;
                                        row.CatalogNodeId  = catalogNode.CatalogNodeId;

                                        if (sortOrder >= 0)
                                        {
                                            row.SortOrder = sortOrder;
                                        }
                                        else
                                        {
                                            row.SortOrder = 0;
                                        }

                                        catalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row);
                                    }
                                }
                            }
                        }

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

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

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

            return(entryRow.CatalogEntryId);
        }