Exemple #1
0
        private void UpdateRecord()
        {
            var xmlData = GenXmlFunctions.GetGenXml(rpData, "", StoreSettings.Current.FolderImagesMapPath);
            var objInfo = new NBrightInfo();

            objInfo.ItemID   = -1;
            objInfo.TypeCode = "POSTDATA";
            objInfo.XMLData  = xmlData;
            var settings = objInfo.ToDictionary(); // put the fieds into a dictionary, so we can get them easy.

            // check we don't have an invalid parentitemid
            var parentitemid = objInfo.GetXmlPropertyInt("genxml/dropdownlist/ddlparentcatid");
            var strOut       = "No Category ID ('itemid' hidden fields needed on input form)";

            if (settings.ContainsKey("itemid"))
            {
                if (parentitemid != Convert.ToInt32(settings["itemid"]))
                {
                    var catData = CategoryUtils.GetCategoryData(Convert.ToInt32(settings["itemid"]), StoreSettings.Current.EditLanguage);

                    // check we've not put a category under it's child
                    if (IsParentInChildren(catData, parentitemid))
                    {
                        NBrightBuyUtils.SetNotfiyMessage(ModuleId, "categoryactionsave", NotifyCode.fail);
                    }
                    else
                    {
                        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(objInfo);

                        if (!String.IsNullOrEmpty(Edittype) && Edittype.ToLower() == "group")
                        {
                            var grptype = objInfo.GetXmlProperty("genxml/dropdownlist/ddlparentcatid");
                            var grp     = ModCtrl.GetByGuidKey(PortalSettings.PortalId, -1, "GROUP", grptype);
                            if (grp != null)
                            {
                                var newGuidKey = objInfo.GetXmlProperty("genxml/textbox/propertyref");
                                if (newGuidKey != "")
                                {
                                    newGuidKey = GetUniqueGuidKey(catData.CategoryId, Utils.UrlFriendly(newGuidKey));
                                }
                                catData.DataRecord.GUIDKey = newGuidKey;
                                catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", newGuidKey);
                                catData.DataRecord.ParentItemId = grp.ItemID;
                                // list done using ddlgrouptype, in  GetCatList
                                catData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", grptype);
                                catData.Save();
                                NBrightBuyUtils.RemoveModCachePortalWide(PortalId);
                            }
                        }
                        else
                        {
                            // 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(PortalId, Convert.ToInt32(settings["itemid"])); // do validate so we update all refs and children refs
                            NBrightBuyUtils.RemoveModCachePortalWide(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);
                            }
                        }

                        NBrightBuyUtils.SetNotfiyMessage(ModuleId, "categoryactionsave", NotifyCode.ok);
                    }
                }
                else
                {
                    NBrightBuyUtils.SetNotfiyMessage(ModuleId, "categoryactionsave", NotifyCode.fail);
                }
            }
            NBrightBuyUtils.RemoveModCachePortalWide(PortalId); //clear any cache
        }
Exemple #2
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("");
        }
Exemple #3
0
        private void SaveAll()
        {
            foreach (RepeaterItem rtnItem in rpData.Items)
            {
                var isdirty = GenXmlFunctions.GetField(rtnItem, "isdirty");
                var itemid  = GenXmlFunctions.GetField(rtnItem, "itemid");
                if (isdirty == "true" && Utils.IsNumeric(itemid))
                {
                    var catData = CategoryUtils.GetCategoryData(Convert.ToInt32(itemid), StoreSettings.Current.EditLanguage);
                    if (catData.Exists)
                    {
                        var chkishidden = GenXmlFunctions.GetField(rtnItem, "chkishidden");
                        var catname     = GenXmlFunctions.GetField(rtnItem, "txtcategoryname");
                        catData.DataRecord.SetXmlProperty("genxml/checkbox/chkishidden", chkishidden);

                        if (!String.IsNullOrEmpty(Edittype) && Edittype.ToLower() == "group")
                        {
                            var propertyref = GenXmlFunctions.GetField(rtnItem, "propertyref");
                            if (propertyref != "")
                            {
                                catData.DataRecord.SetXmlProperty("genxml/textbox/propertyref", propertyref);
                                catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", propertyref);
                            }
                            var grptype = catData.DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype");
                            var grp     = ModCtrl.GetByGuidKey(PortalSettings.PortalId, -1, "GROUP", grptype);
                            if (grp != null)
                            {
                                catData.ParentItemId = grp.ItemID;
                                ModCtrl.Update(catData.DataRecord);
                            }
                        }
                        else
                        {
                            // 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 == "")
                            {
                                catref = Utils.GetUniqueKey().ToLower();
                                catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                                catData.DataRecord.GUIDKey = catref;
                            }
                            ModCtrl.Update(catData.DataRecord);
                        }

                        catData.DataLangRecord.SetXmlProperty("genxml/textbox/txtcategoryname", catname);
                        ModCtrl.Update(catData.DataLangRecord);
                        if (catname != "")
                        {
                            // update all language records that have no name
                            foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
                            {
                                var catLangUpd = CategoryUtils.GetCategoryData(Convert.ToInt32(itemid), lang);
                                if (catLangUpd.DataLangRecord != null && catLangUpd.Info.GetXmlProperty("genxml/lang/genxml/textbox/txtcategoryname") == "")
                                {
                                    catLangUpd.DataLangRecord.SetXmlProperty("genxml/textbox/txtcategoryname", catname);
                                    ModCtrl.Update(catLangUpd.DataLangRecord);
                                }
                            }
                        }

                        catData.Save();
                        NBrightBuyUtils.RemoveModCachePortalWide(PortalId);                   // clear cache before validate lang, so we pickup new changes to name.
                        CategoryUtils.ValidateLangaugeRef(PortalId, Convert.ToInt32(itemid)); // do validate so we update all refs and children refs
                    }
                }
            }
        }