Example #1
0
        public static void CopySystemPluginsToPortal()
        {
            var objCtrl = new NBrightBuyController();
            var rtnList = objCtrl.GetList(99999, -1, "PLUGIN", "", "order by nb1.xmldata.value('(genxml/hidden/index)[1]','float')");

            foreach (var p in rtnList)
            {
                var existingrecord = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PLUGIN", p.GUIDKey);
                if (existingrecord == null)
                {
                    var filepath = HttpContext.Current.Server.MapPath(p.GetXmlProperty("genxml/textbox/path"));
                    if (File.Exists(filepath))
                    {
                        p.ItemID   = -1;
                        p.PortalId = PortalSettings.Current.PortalId;
                        objCtrl.Update(p);
                    }
                    else
                    {
                        objCtrl.Delete(p.ItemID);
                    }
                }
            }
            PluginUtils.ResequenceRecords();
        }
Example #2
0
 public void DeleteUserData()
 {
     //remove DB record
     var modCtrl = new NBrightBuyController();
     modCtrl.Delete(Info.ItemID);
     Exists = false;
 }
Example #3
0
        public void DeleteUserData()
        {
            //remove DB record
            var modCtrl = new NBrightBuyController();

            modCtrl.Delete(Info.ItemID);
            Exists = false;
        }
        /// <summary>
        /// Rebuild the CATCASCADE index records for a single category
        /// </summary>
        /// <param name="categoryid"></param>
        private void ReIndexSingleCascade(int categoryid)
        {
            if (categoryid > 0)
            {
                //get all category product ids from catxref sub category records.
                var xrefList       = new List <NBrightInfo>();
                var prodItemIdList = xrefList.Select(r => r.ParentItemId).ToList();
                var catList        = new List <GroupCategoryData>();
                var subCats        = GetSubCategoryList(catList, categoryid);
                foreach (var c in subCats)
                {
                    xrefList = _objCtrl.GetList(_portalId, -1, "CATXREF", " and xrefitemid = " + c.categoryid.ToString(""));
                    prodItemIdList.AddRange(xrefList.Select(r => r.ParentItemId));
                }
                //Get the current catascade records
                xrefList = _objCtrl.GetList(_portalId, -1, "CATCASCADE", " and xrefitemid = " + categoryid.ToString(""));
                var casacdeProdItemIdList = xrefList.Select(r => r.ParentItemId).ToList();

                //Update the catcascade records.
                foreach (var prodId in prodItemIdList)
                {
                    AddCatCascadeRecord(categoryid, prodId);
                    casacdeProdItemIdList.RemoveAll(i => i == prodId);
                }
                //remove any cascade records that no longer exists
                foreach (var productid in casacdeProdItemIdList)
                {
                    var strGuid = categoryid.ToString("") + "x" + productid.ToString("");
                    var nbi     = _objCtrl.GetByGuidKey(_portalId, -1, "CATCASCADE", strGuid);
                    if (nbi != null)
                    {
                        _objCtrl.Delete(nbi.ItemID);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Search filesystem for any new plugins that have been added. Removed any deleted ones.
        /// </summary>
        public static void UpdateSystemPlugins()
        {
            // Add new plugins
            var updated             = false;
            var pluginfoldermappath = System.Web.Hosting.HostingEnvironment.MapPath(StoreSettings.NBrightBuyPath() + "/Plugins");

            if (pluginfoldermappath != null && Directory.Exists(pluginfoldermappath))
            {
                var objCtrl = new NBrightBuyController();
                var flist   = Directory.GetFiles(pluginfoldermappath, "*.xml");
                foreach (var f in flist)
                {
                    if (f.EndsWith(".xml"))
                    {
                        var datain = File.ReadAllText(f);
                        try
                        {
                            var nbi = new NBrightInfo();
                            nbi.XMLData = datain;
                            // check if we are injecting multiple
                            var nodlist = nbi.XMLDoc.SelectNodes("genxml");
                            if (nodlist != null && nodlist.Count > 0)
                            {
                                foreach (XmlNode nod in nodlist)
                                {
                                    var nbi2 = new NBrightInfo();
                                    nbi2.XMLData      = nod.OuterXml;
                                    nbi2.ItemID       = -1;
                                    nbi2.GUIDKey      = nbi.GetXmlProperty("genxml/textbox/ctrl");
                                    nbi2.PortalId     = 99999;
                                    nbi2.Lang         = "";
                                    nbi2.ParentItemId = 0;
                                    nbi2.ModuleId     = -1;
                                    nbi2.XrefItemId   = 0;
                                    nbi2.UserId       = 0;
                                    nbi2.TypeCode     = "PLUGIN";

                                    // check if record exists (should NOT) but lets replace if it does.
                                    var existingrecord = objCtrl.GetByGuidKey(-1, -1, "PLUGIN", nbi2.GUIDKey);
                                    if (existingrecord != null)
                                    {
                                        nbi2.ItemID = existingrecord.ItemID;
                                        if (nbi2.GetXmlPropertyBool("genxml/delete"))
                                        {
                                            objCtrl.Delete(existingrecord.ItemID);
                                        }
                                        else
                                        {
                                            objCtrl.Update(nbi2);
                                            updated = true;
                                        }
                                    }
                                    else
                                    {
                                        objCtrl.Update(nbi2);
                                        updated = true;
                                    }
                                }
                            }
                            if (updated)
                            {
                                File.Delete(f);
                            }
                        }
                        catch (Exception)
                        {
                            // data might not be XML complient (ignore)
                        }
                    }
                }
            }

            if (updated)
            {
                CopySystemPluginsToPortal();
                ClearPluginCache(PortalSettings.Current.PortalId);
            }
        }
Example #6
0
        public int Validate()
        {
            var errorcount = 0;
            var objCtrl    = new NBrightBuyController();

            DataRecord.ValidateXmlFormat();
            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                {
                    DataLangRecord        = (NBrightInfo)l[0].Clone();
                    DataLangRecord.ItemID = -1;
                    DataLangRecord.Lang   = _lang;
                    DataLangRecord.ValidateXmlFormat();
                    objCtrl.Update(DataLangRecord);
                }
            }

            var defaultname = Name;

            if (defaultname == "")
            {
                // find a valid default name
                foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
                {
                    var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                    if (l.Count == 1)
                    {
                        var nbi2 = (NBrightInfo)l[0];
                        if (nbi2.GetXmlProperty("genxml/textbox/groupname") != "")
                        {
                            defaultname = nbi2.GetXmlProperty("genxml/textbox/groupname");
                            Name        = defaultname;
                            Save();
                            break;
                        }
                    }
                }
            }

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
            {
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang   = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }

                if (l.Count == 1)
                {
                    var nbi2 = (NBrightInfo)l[0];
                    if (nbi2.GetXmlProperty("genxml/textbox/groupname") == "")
                    {
                        // if we have no name, use the default name we found early to update.
                        nbi2.SetXmlProperty("genxml/textbox/groupname", defaultname);
                        objCtrl.Update(nbi2);
                    }
                }

                if (l.Count > 1)
                {
                    // we have more records than should exists, remove any old ones.
                    var l2 = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp = 1;
                    foreach (var i in l2)
                    {
                        if (lp >= 2)
                        {
                            objCtrl.Delete(i.ItemID);
                        }
                        lp += 1;
                    }
                }
            }

            if (Ref == "")
            {
                Ref = DataRecord.GUIDKey;
                objCtrl.Update(DataRecord);
            }

            // add required field values to make getting group easier.
            if (Ref != "" && DataRecord.GUIDKey != Ref)
            {
                DataRecord.GUIDKey = Ref;
                objCtrl.Update(DataRecord);
            }

            // check we have a groupt type, it might be missing if upgraded.
            if (Type == "")
            {
                if (Ref == "cat")
                {
                    Type = "2";
                }
                else
                {
                    Type = "1";
                }
                objCtrl.Update(DataRecord);
            }


            return(errorcount);
        }
Example #7
0
 public void Delete()
 {
     _objCtrl.Delete(DataRecord.ItemID);
 }
Example #8
0
 public void DeleteCart()
 {
     //remove DB record
     var modCtrl = new NBrightBuyController();
     modCtrl.Delete(_entryId);
 }
Example #9
0
        public int Validate()
        {
            var errorcount = 0;
            var objCtrl = new NBrightBuyController();

            DataRecord.ValidateXmlFormat();
            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                {
                    DataLangRecord = (NBrightInfo)l[0].Clone();
                    DataLangRecord.ItemID = -1;
                    DataLangRecord.Lang = _lang;
                    DataLangRecord.ValidateXmlFormat();
                    objCtrl.Update(DataLangRecord);
                }
            }

            var defaultname = Name;
            if (defaultname == "")
            {
                // find a valid default name
                foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
                {
                    var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                    if (l.Count == 1)
                    {
                        var nbi2 = (NBrightInfo) l[0];
                        if (nbi2.GetXmlProperty("genxml/textbox/groupname") != "")
                        {
                            defaultname = nbi2.GetXmlProperty("genxml/textbox/groupname");
                            Name = defaultname;
                            Save();
                            break;
                        }
                    }
                }
            }

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
            {
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }

                if (l.Count == 1)
                {
                    var nbi2 = (NBrightInfo) l[0];
                    if (nbi2.GetXmlProperty("genxml/textbox/groupname") == "")
                    {
                        // if we have no name, use the default name we found early to update.
                        nbi2.SetXmlProperty("genxml/textbox/groupname", defaultname);
                        objCtrl.Update(nbi2);
                    }
                }

                if (l.Count > 1)
                {
                    // we have more records than should exists, remove any old ones.
                    var l2 = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp = 1;
                    foreach (var i in l2)
                    {
                        if (lp >= 2) objCtrl.Delete(i.ItemID);
                        lp += 1;
                    }
                }
            }

            // add required field values to make getting group easier.
            if (DataRecord.GUIDKey != Ref)
            {
                DataRecord.GUIDKey = Ref;
                objCtrl.Update(DataRecord);
            }

            return errorcount;
        }
Example #10
0
        public int Validate()
        {
            var errorcount = 0;

            // default any undefined group type as category (I think quickcategory v1.0.0 plugin causes this)
            if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype") == "")
            {
                DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", "cat");
                _objCtrl.Update(DataRecord);
            }

            if (GroupType == "cat")
            {
                // the base category ref cannot have language dependant refs, we therefore just use a unique key
                var catref = DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                if (catref == "" || DataRecord.GUIDKey == "")
                {
                    catref = Utils.GetUniqueKey().ToLower();
                    DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                    DataRecord.GUIDKey = catref;
                    errorcount        += 1;
                }

                if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlparentcatid") != DataRecord.ParentItemId.ToString())
                {
                    DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", DataRecord.ParentItemId.ToString());
                }
            }

            DataRecord.ValidateXmlFormat();

            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = _objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                {
                    DataLangRecord        = (NBrightInfo)l[0].Clone();
                    DataLangRecord.ItemID = -1;
                    DataLangRecord.Lang   = _lang;
                    DataLangRecord.ValidateXmlFormat();
                    _objCtrl.Update(DataLangRecord);
                }
            }

            // fix image
            var imgpath       = DataRecord.GetXmlProperty("genxml/hidden/imagepath");
            var imgurl        = DataRecord.GetXmlProperty("genxml/hidden/imageurl");
            var imagefilename = Path.GetFileName(imgpath);

            if (StoreSettings.Current != null) // current setting not valid in Scheduler.
            {
                if (!imgpath.StartsWith(StoreSettings.Current.FolderImagesMapPath))
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imagepath", StoreSettings.Current.FolderImagesMapPath.TrimEnd('\\') + "\\" + imagefilename);
                    errorcount += 1;
                }
                if (imagefilename == "")
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imagepath", "");
                    errorcount += 1;
                }
                if (!imgurl.StartsWith(StoreSettings.Current.FolderImages))
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imageurl", StoreSettings.Current.FolderImages.TrimEnd('/') + "/" + imagefilename);
                    errorcount += 1;
                }
            }
            if (imagefilename == "")
            {
                DataRecord.SetXmlProperty("genxml/hidden/imageurl", "");
                errorcount += 1;
            }

            // check guidkey is correct
            if (DataRecord.GUIDKey != CategoryRef)
            {
                DataRecord.GUIDKey = CategoryRef;
                errorcount        += 1;
            }

            if (errorcount > 0)
            {
                _objCtrl.Update(DataRecord);                 // update if we find a error
            }
            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                var l = _objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang   = lang;
                    _objCtrl.Update(nbi);
                    errorcount += 1;
                }
                if (l.Count > 1)
                {
                    // we have more records than shoudl exists, remove any old ones.
                    var l2 = _objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp = 1;
                    foreach (var i in l2)
                    {
                        if (lp >= 2)
                        {
                            _objCtrl.Delete(i.ItemID);
                        }
                        lp += 1;
                    }
                }
            }

            // Build langauge refs
            if (GroupType == "cat")
            {
                var updaterequired = CategoryUtils.ValidateLangaugeRef(_portalId, CategoryId);
                if (updaterequired)
                {
                    // the catref has been updated, so reload the datarecord
                    DataLangRecord = _objCtrl.GetDataLang(CategoryId, _lang);
                }
            }

            // fix groups with mismatching ddlgrouptype
            if (GroupType != "cat")
            {
                var grp = _objCtrl.Get(DataRecord.ParentItemId, "GROUP");
                if (grp != null)
                {
                    if (grp.GUIDKey != GroupType)
                    {
                        DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", grp.GUIDKey);
                        _objCtrl.Update(DataRecord);
                        errorcount += 1;
                    }
                }
            }


            return(errorcount);
        }
Example #11
0
 public void Delete()
 {
     // remove any cache
     ProductUtils.RemoveProductDataCache(DataRecord.ItemID, _lang);
     //delete and allow DB to cascade delete
     var objCtrl = new NBrightBuyController();
     objCtrl.Delete(DataRecord.ItemID);
 }
Example #12
0
        public int Validate()
        {
            var errorcount = 0;

            var objCtrl = new NBrightBuyController();

            SetGuidKey();
            objCtrl.Update(DataRecord);

            DataRecord.ValidateXmlFormat();
            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(_portalId, -1, "PRDLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                    DataLangRecord = (NBrightInfo) l[0].Clone();
                else
                    DataLangRecord = new NBrightInfo(true);

                DataLangRecord.ItemID = -1;
                DataLangRecord.ValidateXmlFormat();
                DataLangRecord.TypeCode = "PRDLANG";
                DataLangRecord.ParentItemId = Info.ItemID;
                DataLangRecord.Lang = _lang;
                objCtrl.Update(DataLangRecord);
            }

            //Fix image paths
            var lp = 1;
            foreach (var i in Imgs)
            {
                if (!i.GetXmlProperty("genxml/hidden/imageurl").StartsWith(_storeSettings.FolderImages))
                {
                    var iname = Path.GetFileName(i.GetXmlProperty("genxml/hidden/imagepath"));
                    DataRecord.SetXmlProperty("genxml/imgs/genxml[" + lp + "]/hidden/imageurl", _storeSettings.FolderImages.TrimEnd('/') + "/" + iname);
                    errorcount += 1;
                }
                if (!i.GetXmlProperty("genxml/hidden/imagepath").StartsWith(_storeSettings.FolderImagesMapPath))
                {
                    var iname = Path.GetFileName(i.GetXmlProperty("genxml/hidden/imagepath"));
                    DataRecord.SetXmlProperty("genxml/imgs/genxml[" + lp + "]/hidden/imagepath", _storeSettings.FolderImagesMapPath.TrimEnd('\\') + "\\" + iname);
                    errorcount += 1;
                }
                lp += 1;
            }
            //Fix document paths
            lp = 1;
            foreach (var d in Docs)
            {
                if (!d.GetXmlProperty("genxml/hidden/filepath").StartsWith(_storeSettings.FolderDocumentsMapPath))
                {
                    DataRecord.SetXmlProperty("genxml/docs/genxml/hidden/filepath", _storeSettings.FolderDocumentsMapPath.TrimEnd('\\') + "\\" + d.GetXmlProperty("genxml/textbox/txtfilename"));
                    errorcount += 1;
                }
                lp += 1;
            }

            if (errorcount > 0) objCtrl.Update(DataRecord); // update if we find a error

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                var l = objCtrl.GetList(_portalId, -1, "PRDLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }
                if (l.Count > 1)
                {
                    // we have more records than shoudl exists, remove any old ones.
                    var l2 = objCtrl.GetList(_portalId, -1, "PRDLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp2 = 1;
                    foreach (var i in l2)
                    {
                        if (lp2 >= 2) objCtrl.Delete(i.ItemID);
                        lp2 += 1;
                    }
                }
            }

            return errorcount;
        }
Example #13
0
        public int Validate()
        {
            var errorcount = 0;

            var objCtrl = new NBrightBuyController();

            SetGuidKey();
            objCtrl.Update(DataRecord);

            DataRecord.ValidateXmlFormat();
            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(_portalId, -1, _typeLangCode, " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                    DataLangRecord = (NBrightInfo) l[0].Clone();
                else
                    DataLangRecord = new NBrightInfo(true);

                DataLangRecord.ItemID = -1;
                DataLangRecord.ValidateXmlFormat();
                DataLangRecord.TypeCode = _typeLangCode;
                DataLangRecord.ParentItemId = Info.ItemID;
                DataLangRecord.Lang = _lang;
                objCtrl.Update(DataLangRecord);
            }

            //Fix image paths
            var lp = 1;
            foreach (var i in Imgs)
            {
                if (!File.Exists(i.GetXmlProperty("genxml/hidden/imagepath"))) // products shared across portals may have different image path.
                {
                    if (!i.GetXmlProperty("genxml/hidden/imageurl").StartsWith(_storeSettings.FolderImages))
                    {
                        var iname = Path.GetFileName(i.GetXmlProperty("genxml/hidden/imagepath"));
                        DataRecord.SetXmlProperty("genxml/imgs/genxml[" + lp + "]/hidden/imageurl", _storeSettings.FolderImages.TrimEnd('/') + "/" + iname);
                        errorcount += 1;
                    }
                    if (!i.GetXmlProperty("genxml/hidden/imagepath").StartsWith(_storeSettings.FolderImagesMapPath))
                    {
                        var iname = Path.GetFileName(i.GetXmlProperty("genxml/hidden/imagepath"));
                        DataRecord.SetXmlProperty("genxml/imgs/genxml[" + lp + "]/hidden/imagepath", _storeSettings.FolderImagesMapPath.TrimEnd('\\') + "\\" + iname);
                        errorcount += 1;
                    }
                }
                lp += 1;
            }
            //Fix document paths
            lp = 1;
            foreach (var d in Docs)
            {
                if (!File.Exists(d.GetXmlProperty("genxml/hidden/filepath"))) // products shared across portals may have different path.
                {
                    if (!d.GetXmlProperty("genxml/hidden/filepath").StartsWith(_storeSettings.FolderDocumentsMapPath))
                    {
                        var fname = d.GetXmlProperty("genxml/textbox/txtfilename");
                        if (d.GetXmlProperty("genxml/hidden/filerelpath") != "")
                        {
                            fname = Path.GetFileName("D:" + d.GetXmlProperty("genxml/hidden/filerelpath").Replace("/", "\\"));
                        }
                        DataRecord.SetXmlProperty("genxml/docs/genxml/hidden/filepath", _storeSettings.FolderDocumentsMapPath.TrimEnd('\\') + "\\" + fname);
                        errorcount += 1;
                    }
                }
                lp += 1;
            }

            if (errorcount > 0) objCtrl.Update(DataRecord); // update if we find a error

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                var l = objCtrl.GetList(_portalId, -1, _typeLangCode, " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }
                if (l.Count > 1)
                {
                    // we have more records than should exists, remove any old ones.
                    var l2 = objCtrl.GetList(_portalId, -1, _typeLangCode, " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp2 = 1;
                    foreach (var i in l2)
                    {
                        if (lp2 >= 2) objCtrl.Delete(i.ItemID);
                        errorcount += 1;
                        lp2 += 1;
                    }
                }
            }

            // remove duplicate category xrefs.
            var catlist = GetCategories();
            foreach (var c in catlist)
            {
                var l = objCtrl.GetList(_portalId, -1, "CATXREF", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.XrefItemId = " + c.categoryid.ToString(""));
                if (l.Count > 1)
                {
                    var catlp = 0;
                    foreach (var i in l)
                    {
                        if (catlp >= 1)
                        {
                            objCtrl.Delete(i.ItemID);
                            errorcount += 1;
                        }
                        catlp += 1;
                    }
                }
            }

            // remove duplicate catcascade records
            var cascadeList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATCASCADE", " and NB1.ParentItemId = " + Info.ItemID.ToString("") );
            foreach (var c in cascadeList)
            {
                var l2 = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATCASCADE", " and GUIDKey = '" + c.GUIDKey + "'");
                if (l2.Count > 1)
                {
                    for (int i = 1; i < l2.Count; i++)
                    {
                        objCtrl.Delete(l2[i].ItemID);
                        errorcount += 1;
                    }
                }
            }

            // remove any unlinked catacscade records
            cascadeList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATCASCADE", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.XrefItemId = 0");
            foreach (var c in cascadeList)
            {
                objCtrl.Delete(c.ItemID);
                errorcount += 1;
            }

            return errorcount;
        }
        private String DeleteData(HttpContext context)
        {
            try
            {
                var objCtrl = new NBrightBuyController();

                //get uploaded params
                var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
                var itemid = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
                if (Utils.IsNumeric(itemid))
                {
                    // delete DB record
                    objCtrl.Delete(Convert.ToInt32(itemid));

                    NBrightBuyUtils.RemoveModCache(-2);

                }
                return "";

            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
Example #15
0
        public int Validate()
        {
            var errorcount = 0;
            var objCtrl = new NBrightBuyController();

            // default any undefined group type as category (I think quickcategory v1.0.0 plugin causes this)
            if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype") == "")
            {
                DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", "cat");
                objCtrl.Update(DataRecord);
            }

            if (GroupType == "cat")
            {
                // the base category ref cannot have language dependant refs, we therefore just use a unique key
                var catref = DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                if (catref == "" || DataRecord.GUIDKey == "")
                {
                    catref = Utils.GetUniqueKey().ToLower();
                    DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                    DataRecord.GUIDKey = catref;
                    errorcount += 1;
                }

                if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlparentcatid") != DataRecord.ParentItemId.ToString())
                {
                    DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", DataRecord.ParentItemId.ToString());
                }

            }

            DataRecord.ValidateXmlFormat();

            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                {
                    DataLangRecord = (NBrightInfo)l[0].Clone();
                    DataLangRecord.ItemID = -1;
                    DataLangRecord.Lang = _lang;
                    DataLangRecord.ValidateXmlFormat();
                    objCtrl.Update(DataLangRecord);
                }
            }

            // fix image
            var imgpath = DataRecord.GetXmlProperty("genxml/hidden/imagepath");
            var imgurl = DataRecord.GetXmlProperty("genxml/hidden/imageurl");
            var imagefilename = Path.GetFileName(imgpath);
            if (!imgpath.StartsWith(StoreSettings.Current.FolderImagesMapPath))
            {
                    DataRecord.SetXmlProperty("genxml/hidden/imagepath", StoreSettings.Current.FolderImagesMapPath.TrimEnd('\\') + "\\" + imagefilename);
                errorcount += 1;
            }
            if (imagefilename == "")
            {
                DataRecord.SetXmlProperty("genxml/hidden/imagepath", "");
                errorcount += 1;
            }
            if (!imgurl.StartsWith(StoreSettings.Current.FolderImages))
            {
                    DataRecord.SetXmlProperty("genxml/hidden/imageurl", StoreSettings.Current.FolderImages.TrimEnd('/') + "/" + imagefilename);
                errorcount += 1;
            }
            if (imagefilename == "")
            {
                DataRecord.SetXmlProperty("genxml/hidden/imageurl", "");
                errorcount += 1;
            }

            // check guidkey is correct
            if (DataRecord.GUIDKey != CategoryRef)
            {
                DataRecord.GUIDKey = CategoryRef;
                errorcount += 1;
            }

            if (errorcount > 0) objCtrl.Update(DataRecord); // update if we find a error

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                var l = objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }
                if (l.Count > 1)
                {
                    // we have more records than shoudl exists, remove any old ones.
                    var l2 = objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp = 1;
                    foreach (var i in l2)
                    {
                      if (lp >=2) objCtrl.Delete(i.ItemID);
                      lp += 1;
                    }
                }
            }

            // Build langauge refs
            if (GroupType == "cat")
            {
                var updaterequired = CategoryUtils.ValidateLangaugeRef(_portalId,CategoryId);
                if (updaterequired)
                {
                    // the catref has been updated, so reload the datarecord
                    DataLangRecord = objCtrl.GetDataLang(CategoryId, _lang);
                }
            }

            // fix groups with mismatching ddlgrouptype
            if (GroupType != "cat")
            {
                var grp = objCtrl.Get(DataRecord.ParentItemId, "GROUP");
                if (grp != null)
                {
                    if (grp.GUIDKey != GroupType)
                    {
                        DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", grp.GUIDKey);
                        objCtrl.Update(DataRecord);
                        errorcount += 1;
                    }
                }
            }

            return errorcount;
        }
        private String DeleteData(HttpContext context)
        {
            var objCtrl = new NBrightBuyController();

            //get uploaded params
            var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
            var itemid = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
            if (Utils.IsNumeric(itemid))
            {
                var nbi = objCtrl.Get(Convert.ToInt32(itemid));
                if (nbi != null)
                {
                    var typecode = nbi.TypeCode;

                    // run the promo before delete, so we remove any promo data that may exist.
                    if (typecode == "CATEGORYPROMO")
                    {
                        PromoUtils.RemoveGroupProductPromo(PortalSettings.Current.PortalId, Convert.ToInt32(itemid));
                    }
                    if (typecode == "MULTIBUYPROMO")
                    {
                        PromoUtils.RemoveMultiBuyProductPromo(PortalSettings.Current.PortalId, Convert.ToInt32(itemid));
                    }
                }

                // delete DB record
                objCtrl.Delete(Convert.ToInt32(itemid));

                NBrightBuyUtils.RemoveModCache(-2);

            }
            return "";
        }