public BlogSettingsViewModel()
        {
            using (var context = new DataContext())
            {
                Settings = context.BlogSettings.FirstOrDefault();

                // Set some initial values if none are found.
                if (Settings == null)
                {
                    Utils.SiteSettingsUtils.SetDefaultBlogSettings();
                    Settings = context.BlogSettings.FirstOrDefault();
                }
            }
        }
        public JsonResult BlogSettings(BlogSettings entity)
        {
            var result = new JsonResult();

            using (var context = new DataContext())
            {
                var blogSettings = context.BlogSettings.FirstOrDefault();
                if (blogSettings != null)
                {
                    blogSettings.BlogTitle = entity.BlogTitle;
                    blogSettings.DisableAllCommentsGlobal = entity.DisableAllCommentsGlobal;
                    blogSettings.DisqusShortName = entity.DisqusShortName;
                    blogSettings.FacebookAppId = entity.FacebookAppId;
                    blogSettings.MaxBlogsOnHomepageBeforeLoad = entity.MaxBlogsOnHomepageBeforeLoad;
                    blogSettings.ShowDisqusComents = entity.ShowDisqusComents;
                    blogSettings.ShowFacebookComments = entity.ShowFacebookComments;
                    blogSettings.ShowFacebookLikeButton = entity.ShowFacebookLikeButton;

                    context.SaveChanges();
                }
            }

            return result;
        }
Ejemplo n.º 3
0
        public static void SetDefaultBlogSettings()
        {
            using (var context = new DataContext())
            {
                var settings = new BlogSettings()
                {
                    BlogTitle = "My Blog",
                    DisableAllCommentsGlobal = false,
                    MaxBlogsOnHomepageBeforeLoad = 20
                };

                context.BlogSettings.Add(settings);

                context.SaveChanges();
            }
        }