コード例 #1
0
        public String CategorySave(HttpContext context, string editLangCurrent)
        {
            if (NBrightBuyUtils.CheckManagerRights())
            {
                EditLangCurrent = editLangCurrent;
                var ajaxInfo     = NBrightBuyUtils.GetAjaxFields(context);
                var parentitemid = ajaxInfo.GetXmlPropertyInt("genxml/dropdownlist/ddlparentcatid");
                var catid        = ajaxInfo.GetXmlPropertyInt("genxml/hidden/itemid");
                if (catid > 0)
                {
                    if (parentitemid != catid)
                    {
                        var catData = new CategoryData(catid, EditLangCurrent);

                        // check we've not put a category under it's child
                        if (!IsParentInChildren(catData, parentitemid))
                        {
                            var catDirectList   = catData.GetDirectArticles();
                            var oldparentitemId = catData.ParentItemId;
                            if (parentitemid != oldparentitemId)
                            {
                                // remove articles for category, so we realign the cascade records.
                                foreach (var p in catDirectList)
                                {
                                    var prdData = new ProductData(p.ParentItemId, p.PortalId, p.Lang);
                                    prdData.RemoveCategory(catData.CategoryId);
                                }
                            }

                            catData.Update(ajaxInfo);

                            // the base category ref cannot have language dependant refs, we therefore just use a unique key
                            var catref = catData.DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                            if (catref == "")
                            {
                                if (catData.DataRecord.GUIDKey == "")
                                {
                                    catref = Utils.GetUniqueKey().ToLower();
                                    catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                                    catData.DataRecord.GUIDKey = catref;
                                }
                                else
                                {
                                    catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catData.DataRecord.GUIDKey);
                                }
                            }
                            catData.Save();
                            CategoryUtils.ValidateLangaugeRef(PortalSettings.Current.PortalId, catid); // do validate so we update all refs and children refs
                            NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);

                            if (parentitemid != oldparentitemId)
                            {
                                // all all articles for category. so we realign the cascade records.
                                foreach (var p in catDirectList)
                                {
                                    var prdData = new ProductData(p.ParentItemId, p.PortalId, p.Lang);
                                    prdData.AddCategory(catData.CategoryId);
                                }
                            }
                        }
                    }
                }
                DataCache.ClearCache();
                NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
            }
            return("");
        }