Beispiel #1
0
 public WritaSettings LoadSettings()
 {
     using (var db = new WritaBlogContext())
     {
         return(db.WritaSettings.Take(1).SingleOrDefault());
     }
 }
Beispiel #2
0
        public void DeletePluginValue(string sid)
        {
            var db     = new WritaBlogContext();
            var plugin = db.WritaPluginSettings.AsQueryable().Where(w => w.Id == sid).SingleOrDefault();

            db.WritaPluginSettings.Remove(plugin);
            db.SaveChanges();
        }
Beispiel #3
0
        public void UpdatePluginValue(string sid, string value)
        {
            var db     = new WritaBlogContext();
            var plugin = db.WritaPluginSettings.AsQueryable().Where(w => w.Id == sid).SingleOrDefault();

            plugin.Value = value;
            db.SaveChanges();
        }
Beispiel #4
0
        public bool DeletePost(string postid)
        {
            var db     = new WritaBlogContext();
            var plugin = db.WritaPosts.AsQueryable().Where(w => w.PostId == postid).SingleOrDefault();

            db.WritaPosts.Remove(plugin);
            db.SaveChanges();
            return(true);
        }
Beispiel #5
0
        public bool DeleteAllPosts()
        {
            var db     = new WritaBlogContext();
            var plugin = db.WritaPosts.AsQueryable().ToList();

            db.WritaPosts.RemoveRange(plugin);
            db.SaveChanges();
            return(true);
        }
Beispiel #6
0
        public WritaUser UpdateUser(WritaUser u)
        {
            var db    = new WritaBlogContext();
            var euser = db.WritaUsers.AsQueryable().Where(w => w.Id == u.Id).SingleOrDefault();

            euser.UserPasswordEncrypted = u.UserPasswordEncrypted;
            db.SaveChanges();
            return(euser);
        }
Beispiel #7
0
        public WritaUser CreateUser(WritaUser u)
        {
            var db = new WritaBlogContext();

            u.Id = System.Guid.NewGuid().ToString();
            db.WritaUsers.Add(u);
            db.SaveChanges();
            return(u);
        }
Beispiel #8
0
        public WritaStats GetStats()
        {
            WritaStats s  = new WritaStats();
            var        db = new WritaBlogContext();

            s.NumberOfPosts       = db.WritaPosts.AsQueryable().Where(w => w.PostType == WritaPostType.BLOGPOST).Count();
            s.NumberOfStaticPages = db.WritaPosts.AsQueryable().Where(w => w.PostType != WritaPostType.BLOGPOST).Count();
            s.LastPostDate        = db.WritaPosts.AsQueryable().Where(w => w.PostType == WritaPostType.BLOGPOST).OrderByDescending(w => w.PostCreated).Take(1).First().PostCreated;

            var config = LoadSettings();

            s.ActiveTheme = config.BlogTheme;
            return(s);
        }
Beispiel #9
0
        public WritaSettings SaveSettings(WritaSettings s)
        {
            using (var db = new WritaBlogContext())
            {
                var x = db.WritaSettings.Take(1).SingleOrDefault();
                x.BlogTheme        = s.BlogTheme;
                x.BlogSummary      = s.BlogSummary;
                x.BlogTitle        = s.BlogTitle;
                x.BlogDefaultEmail = s.BlogDefaultEmail;
                db.SaveChanges();
            }

            return(s);
        }
Beispiel #10
0
        public WritaPost GetPreviousPost(WritaPost p)
        {
            var db = new WritaBlogContext();
            var x  = db.WritaPosts.AsQueryable().Where(w => w.PostCreated < p.PostCreated && w.PostType == WritaPostType.BLOGPOST && w.PostStatus == WritaPostStatus.PUBLISHED).OrderByDescending(w => w.PostCreated).Take(1).ToList();

            if (x.Count == 1)
            {
                return(x[0]);
            }
            else
            {
                return(null);
            }
        }
Beispiel #11
0
        public WritaPluginSetting GetPluginSettings(string PluginName, string Key, string DefaultValue)
        {
            var db     = new WritaBlogContext();
            var exists = db.WritaPluginSettings.AsQueryable().Where(w => w.PluginName == PluginName && w.Key == Key).SingleOrDefault();

            if (exists != null)
            {
                return(exists);
            }
            else
            {
                WritaPluginSetting p = new WritaPluginSetting()
                {
                    Id = System.Guid.NewGuid().ToString(), Key = Key, PluginName = PluginName, Value = DefaultValue
                };
                db.WritaPluginSettings.Add(p);
                db.SaveChanges();

                return(p);
            }
        }
Beispiel #12
0
 public bool CheckInstall(GlobalSettings s)
 {
     try
     {
         using (var db = new WritaBlogContext())
         {
             if (db.WritaPosts.Count() == 0)
             {
                 InstallSet set = InstallHelper.GetInstall();
                 CreatePost(set.homepage);
                 CreatePost(set.firstpost);
                 db.WritaSettings.Add(set.settings);
                 db.SaveChanges();
                 //install.
             }
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #13
0
        public WritaPost CreatePost(WritaPost p)
        {
            using (var db = new WritaBlogContext())
            {
                p.PostId         = System.Guid.NewGuid().ToString();
                p.PostCreated    = DateTime.Now;
                p.PostLastEdited = DateTime.Now;
                p.PostSlug       = p.PostTitle.ToLower().Replace(" ", "-");
                db.WritaPosts.Add(p);
                db.SaveChanges();

                WritaPostContent c = new WritaPostContent();
                c.PostContentId  = System.Guid.NewGuid().ToString();
                c.PostId         = p.PostId;
                c.PostEditDate   = DateTime.Now;
                c.PostEditAuthor = p.PostAuthor;
                c.PostMarkdown   = p.PostContent;

                db.WritaPostContents.Add(c);
                db.SaveChanges();
                return(p);
            }
        }
Beispiel #14
0
        public WritaPost GetPostFromSlug(string slug)
        {
            var db = new WritaBlogContext();

            return(db.WritaPosts.AsQueryable().Where(w => w.PostSlug == slug.ToLower()).SingleOrDefault());
        }
Beispiel #15
0
        public IQueryable <WritaPost> GetAllPosts()
        {
            var db = new WritaBlogContext();

            return(db.WritaPosts.AsQueryable());
        }
Beispiel #16
0
        public WritaPost GetPostFromId(string id)
        {
            var db = new WritaBlogContext();

            return(db.WritaPosts.AsQueryable().Where(w => w.PostId == id).SingleOrDefault());
        }
Beispiel #17
0
        public WritaUser GetUserById(WritaUser u)
        {
            var db = new WritaBlogContext();

            return(db.WritaUsers.AsQueryable().Where(w => w.Id == u.Id).SingleOrDefault());
        }
Beispiel #18
0
        public IQueryable <WritaUser> GetUsers()
        {
            var db = new WritaBlogContext();

            return(db.WritaUsers.AsQueryable());
        }
Beispiel #19
0
        public IQueryable <WritaPost> GetPosts()
        {
            var db = new WritaBlogContext();

            return(db.WritaPosts.AsQueryable().Where(w => w.PostType == WritaPostType.BLOGPOST).AsQueryable());
        }
Beispiel #20
0
        public IQueryable <WritaPluginSetting> GetPluginSettings()
        {
            var db = new WritaBlogContext();

            return(db.WritaPluginSettings.AsQueryable());
        }