Пример #1
0
        /// <summary>
        /// Saves this collection to database
        /// </summary>
        /// <returns><b>true</b> if save is successful, <b>false</b> otherwise</returns>
        public bool Save()
        {
            Database database = Token.Instance.Database;

            //DELETE ANY CATEGORIES THAT APPEAR IN _ORIGVALUE BUT NOT IN CURRENT LIST
            foreach (int categoryId in _OrigValue)
            {
                if (this.IndexOf(categoryId) < 0)
                {
                    using (DbCommand selectCommand = database.GetSqlStringCommand("DELETE FROM ac_CatalogNodes WHERE CategoryId = @categoryId AND CatalogNodeId = @webpageId AND CatalogNodeTypeId = 2"))
                    {
                        database.AddInParameter(selectCommand, "@categoryId", System.Data.DbType.Int32, categoryId);
                        database.AddInParameter(selectCommand, "@webpageId", System.Data.DbType.Int32, _WebpageId);
                        database.ExecuteNonQuery(selectCommand);
                    }
                }
            }
            //ADD ANY CATEGORIES THAT DO NOT APPEAR IN _ORIGVALUE
            foreach (int categoryId in this)
            {
                if (_OrigValue.IndexOf(categoryId) < 0)
                {
                    CatalogNode node = new CatalogNode();
                    node.CategoryId      = categoryId;
                    node.CatalogNodeId   = _WebpageId;
                    node.CatalogNodeType = CommerceBuilder.Catalog.CatalogNodeType.Webpage;
                    node.OrderBy         = -1;
                    node.Save();
                }
            }
            //UPDATE THE ORIGVALUE WITH THE SAVED LIST
            _OrigValue = new List <int>();
            _OrigValue.AddRange(this);
            return(true);
        }
 public static SaveResult Insert(CatalogNode catalogNode)
 {
     return(catalogNode.Save());
 }
 public static SaveResult Update(CatalogNode catalogNode)
 {
     return(catalogNode.Save());
 }