/// <summary>
        /// default constructor
        /// </summary>
        public Category() {
            _categoryid = 0;
            _categoryname = null;
            _categorydescription = null;
            _parentcategoryid = null;

            _ispublished = true;
            _imageurl = null;
            _width = null;
            _height = null;
            _alttext = null;
            _cssClass = null;
            _inserttimestamp = DateTime.Now;
            _updatetimestamp = DateTime.Now;
        }
        protected void Page_Load(object sender, EventArgs e) {

            this._page = (ModuleAdminBasePage)this.Page;
            try {
                CatID = Int64.Parse(Request.Params[PARAM_CATEGORY_ID]);
                Confirmed = Request.Params[PARAM_CONFIRMED];
            } catch {
            }

            if (Confirmed == "true") {

                CatalogueViewModule controller = Module as CatalogueViewModule;

                if (CatID > 0) {
                    cat = controller.CatalogueViewer.GetCategory(controller.Section.Node.Site.Id, controller.Section.Node.Culture, CatID);
                }

                string message = "The category was unable to be deleted. Please try again.";

                if (cat != null) {

                    ctlBreadCrumb.RenderBreadCrumbTrail(controller.CatalogueViewer.GetCategoryView(controller.Section.Node.Site.Id, controller.Section.Node.Culture, CatID).BreadCrumbTrail);
                    cat.IsPublished = false;

					try
					{
						controller.EditService.SaveCategory(controller.Section.Node.Site.Id, cat);
						message = "The category was deleted successfully";
					}
                    catch(Exception ex)
                    {
                    	message = ex.Message;
                    }
                }

                Response.Redirect(CatalogueBrowser.GetBrowserUrl(this, (cat != null) ? cat.ParentNodeID : CatID, message));

            } else {

                //ask them to confirm
                Response.Redirect(String.Format("~/Modules/ECommerce/Admin/Catalogue/ConfirmDelete.aspx{0}", this._page.GetBaseQueryString()) + "&cat=" + CatID);
            }
        }
        public bool MoveCategory(int storeID, Category cat) {
            try {
                this._sessionManager.OpenSession().SaveOrUpdateCopy(cat);
                this._sessionManager.OpenSession().Flush();
            } catch (Exception e) {
                LogManager.GetLogger(GetType()).Error(e);
                return false;
            }

            return true;
        }
 public void SaveCategory(int storeID, Category cat) {
     try {
         var persistentCat = (Category)this._sessionManager.OpenSession().SaveOrUpdateCopy(cat);
         cat.CategoryID = persistentCat.CategoryID;
         this._sessionManager.OpenSession().Flush();
     } catch (Exception e) {
         LogManager.GetLogger(GetType()).Error(e);
     	throw;
     }
 }
        public Category GetUpdatedCategory() {

            ReadRequestParams();
            Category newCategory;

            if (CatID != CATEGORY_ID_NEW) {
                newCategory = controller.CatalogueViewer.GetCategory(1, "en-GB", CatID);//hack
            } else {
                newCategory = new Category();
                newCategory.IsPublished = true;
                newCategory.ParentCategory = controller.CatalogueViewer.GetCategory(1, "en-GB", ParentNodeID);//hack
            }

            newCategory.CategoryDescription = fckDescription.Value;
            newCategory.CategoryName = txtCategoryName.Text;
            newCategory.CssClass = txtCss.Text;
            decimal changeBY = 0;

            try {
                changeBY = Convert.ToDecimal(txtPriceChangePercent.Text);
            } catch {
                changeBY = 0;
            }
               ScaledPriceProcessor priceScaler = new ScaledPriceProcessor();

            if(changeBY > 0){
                ICategoryView view = controller.CatalogueViewer.GetCategoryView(1, "en-GB", CatID);//hack
               if (view.ProductList.Count == 0) {
                   ICategoryView subView;
                   foreach (ICategory node in view.ChildNodes) {
                       subView = controller.CatalogueViewer.GetCategoryView(1, "en-GB", node.NodeID);//hack
                       List<IProductSummary> productList = subView.ProductList;
                       foreach (IProductSummary p in productList) {
                           priceScaler.SaveProductPriceChange(p.ProductID, priceScaler.GenerateScaledPrice(changeBY, p.Price));
                       }
                   }
               } else {

                   List<IProductSummary> productList = view.ProductList;
                   foreach (IProductSummary p in productList) {
                       priceScaler.SaveProductPriceChange(p.ProductID, priceScaler.GenerateScaledPrice(changeBY, p.Price));
                   }
               }
            }

            if (wim.ImageHeight != null && wim.WebImagePath != null) {
                newCategory.Height = Convert.ToInt16(wim.ImageHeight);
                newCategory.Width = Convert.ToInt16(wim.ImageWidth);
                newCategory.Url = WebHelper.GetImageUrl(wim.WebImagePath);
            }

            return newCategory;
        }
        private void MoveUp(Category cat) {

            ICategoryView nodeView = controller.CatalogueViewer.GetCategoryView(controller.Section.Node.Site.Id, controller.Section.Node.Culture, cat.ParentCategory.CategoryID);
            int storeID = controller.Section.Node.Site.Id;

            //Check the sort orders make sense
            short catIndex = GetNodeIndex(cat, nodeView);

            //Make sure it's not the top one
            if (catIndex == 0) {
                return;
            }

            SwapCategories(nodeView, (short) (catIndex - 1));
        }
        private short GetNodeIndex(Category cat, ICategoryView nodeView) {

            short sortOrder = Category.SORT_ORDER_MIN;
            int storeID = controller.Section.Node.Site.Id;
            short catIndex = 0;

            //Perform quick sanity check on sort orders whilst we're at it
            foreach (ICategory node in nodeView.ChildNodes) {

                if (node.SortOrder != sortOrder) {
                    Category catLoop = controller.CatalogueViewer.GetCategory(storeID, "", node.NodeID);
                    catLoop.SortOrder = sortOrder;
                    controller.EditService.MoveCategory(storeID, catLoop);
                }

                //Work out index of our node in list
                if (node.NodeID == cat.NodeID) {
                    catIndex = (short) (sortOrder - Category.SORT_ORDER_MIN);
                }

                sortOrder++;
            }

            return catIndex;
        }
        private void MoveDown(Category cat) {

            ICategoryView nodeView = controller.CatalogueViewer.GetCategoryView(controller.Section.Node.Site.Id, controller.Section.Node.Culture, cat.ParentCategory.CategoryID);

            //Check the sort orders make sense
            short catIndex = GetNodeIndex(cat, nodeView);

            //Make sure it's not the bottom one
            if (catIndex == (nodeView.ChildNodes.Count - 1)) {
                return;
            }

            SwapCategories(nodeView, catIndex);
        }