예제 #1
0
        //[NonPersistent()]
        //public string AbsoluteFileLocation
        //{
        //    get
        //    {
        //        //Gaat soms hier nog de fout in.
        //        if (RelativePath != null)
        //        {
        //            return Site.Path + RelativePath + Name + ".aspx";
        //        }
        //        else
        //        {
        //            return Site.Path + Name + ".aspx";
        //        }
        //    }
        //}

        //[NonPersistent()]
        //public string AbsoluteFileName
        //{
        //    get
        //    {
        //        string path = "";
        //        if (this.RelativePath != null)
        //        {
        //            path = AppDomain.CurrentDomain.BaseDirectory + this.RelativePath.Replace("/", "\\");
        //        }
        //        else
        //        {
        //            path = AppDomain.CurrentDomain.BaseDirectory;
        //        }

        //        string fileName = path + RelativeUrl.Replace("/", "\\");
        //        return fileName;
        //    }
        //}
        #endregion


        #region SAVE, DELETE EN COPY
        public override void Save()
        {
            if (IsNew && WebSessionHelper.CurrentLicense != null && WebSessionHelper.CurrentLicense.HasMaxNumberExceeded("Page"))
            {
                throw new Exception("Kan niet opslaan: licentie heeft maximale aantal pagina's (" + WebSessionHelper.CurrentLicense.MaxNumberOfPages + ") overschreden.");
            }
            this.Name = FileHelper.CleanFileName(this.Name);    //Haal vreemde tekens uit de paginanaam.
            //Er mag maar 1 pagina per forlder de hiome page zijn
            //als deze pagina de homepage is, dan andere uit die folder geen homepage maken
            if (this.IsHomePage)
            {
                string where = "";
                if (this.Folder == null)
                {
                    where = "FK_Folder is null AND IsHomePage='1'";
                }
                else
                {
                    where = "FK_Folder = '" + this.Folder.ID.ToString() + "' AND IsHomePage='1'";
                }

                BaseCollection <CmsPage> Pages = BaseCollection <CmsPage> .Get(where);

                foreach (CmsPage page in Pages)
                {
                    if (page.ID != this.ID)
                    {
                        page.IsHomePage = false;
                        page.Save();
                    }
                }
            }

            //zet pad (wordt opgeslagen in db voor performance)
            if (this.Folder == null && this.GetType() != typeof(Newsletters.Newsletter))
            {
                RelativeUrl = "/" + Name;
            }

            if (this.Folder != null && this.GetType() != typeof(Newsletters.Newsletter))
            {
                RelativeUrl = "/" + Folder.GetCompletePath() + "/" + Name;
            }
            //Relative URL van nieuwsbrief is verhuist naar newsletter.save();
            //unique check
            //workaraound voor mysql: uniek is combi van naam, site en folder
            //als folder leeg is (NULL), gaat uniqueconstraint niet af in mySql
            //hierom in c# checken
            if (this.Folder == null)
            {
                string pageName = this.Name;
                //escape char voor mysql
                pageName = pageName.Replace("'", "''");
                string  sql       = String.Format("FK_Site='{0}' AND FK_Folder IS NULL AND name = '{1}' AND ID != '{2}'", Site.ID, pageName, this.ID);
                CmsPage checkPage = BaseObject.GetFirst <CmsPage>(sql);
                if (checkPage != null)
                {
                    throw new Exception("Er bestaat al een pagina met deze naam.");
                }
            }

            base.Save();

            //this.Publish();
        }