Exemple #1
0
        /// <summary>
        /// Retrieves the home page template model for the current domain.
        /// </summary>
        /// <param name="name">Holds the name of the model type that was retrieved.</param>
        /// <returns>The current domains home page template.</returns>
        public HomePageTemplate RetrieveHomePage(out string name)
        {
            DomainHomePage entity = Query.DomainHomePage(UserCookie.Current.DomainId);

            bool newNeeded = false;

            if (entity == null)
            {
                newNeeded = true;
                entity    = new DomainHomePage()
                {
                    ModelType = "Ribbon",
                    HomePage  = ""
                };
            }

            name = entity.ModelType;

            CachedEditableModel cachedModel = CMSCache.HomePages[entity.ModelType];

            HomePageTemplate homePage = JsonConvert.DeserializeObject(entity.HomePage, cachedModel.ModelType) as HomePageTemplate;

            if (newNeeded)
            {
                homePage = new Framework.Models.HomePage.Ribbon();
            }

            homePage.DisplayLocation = cachedModel.DisplayLocation;
            homePage.EditorLocation  = cachedModel.EditorLocation;

            return(homePage);
        }
Exemple #2
0
        /// <summary>
        /// Saves the home page model into the database.
        /// </summary>
        public SaveResult SaveHomePageModel(HomePageModel model)
        {
            try
            {
                ContentManagementDb db = new ContentManagementDb();

                DomainHomePage homePage = db.DomainHomePages.Find(UserSession.Current.DomainId);

                if (homePage == null)
                {
                    homePage          = db.DomainHomePages.CreateAdd();
                    homePage.DomainId = UserSession.Current.DomainId;
                }

                homePage.ModelType = model.HomePageTemplate;
                homePage.HomePage  = JsonConvert.SerializeObject(model.HomePageTemplateModel);

                db.SaveChanges();

                return(SaveResult.Success);
            }
            catch
            {
                return(SaveResult.Fail);
            }
        }