bool IMetaWeblog.UpdatePost(string postid, string username, string password, Post post, bool publish) { if (ValidateUser(username, password)) { bool result = false; //using (VeritasDataContext con = new VeritasDataContext()) VeritasRepository repo = VeritasRepository.GetInstance(); BlogUser user = repo.GetBlogUserByUserName(CacheHandler.BlogConfigId, username); BlogEntry entry = repo.GetEntryByEntryIDBlogConfigId(CacheHandler.BlogConfigId, Convert.ToInt64(postid)); entry.BlogConfigId = CacheHandler.BlogConfigId; entry.BlogAuthorId = user.BlogUserId; entry.EntryName = EntryTitleLogic.GetEntryNameFromTitle(HttpUtility.HtmlDecode(post.title)); entry.FeedbackCount = 0; entry.PostType = publish ? 1 : 0; entry.Text = HighSlideHandler.UpdateLiveWriterImagesWithHighslide(post.description); entry.Title = HttpUtility.HtmlDecode(post.title); entry.LastUpdateDate = DateTime.Now; repo.Save(); string id = entry.BlogEntryId.ToString(); if (id == postid) { result = true; } repo.SaveEntryCategoryAssociation(CacheHandler.BlogConfigId, entry.BlogEntryId, post.categories); return result; } throw new XmlRpcFaultException(0, "User is not valid!"); }
Post IMetaWeblog.GetPost(string postid, string username, string password) { if (ValidateUser(username, password)) { Post post = new Post(); VeritasRepository repo = VeritasRepository.GetInstance(); BlogEntry entry = repo.GetEntryByEntryIDBlogConfigId(CacheHandler.BlogConfigId, Convert.ToInt64(postid)); if (entry != null) { post.description = entry.Text; post.dateCreated = entry.CreateDate; post.permalink = "http://" + CacheHandler.GetBlogConfig().Host + "/" + entry.EntryName; post.postid = entry.BlogEntryId.ToString(); post.title = entry.Title; post.userid = entry.BlogAuthorId.ToString(); List<string> cats = new List<string>(); foreach (BlogEntryCategory assoc in entry.BlogEntryCategories.ToList()) { cats.Add(assoc.BlogCategory.Title); } post.categories = cats.ToArray(); } return post; } throw new XmlRpcFaultException(0, "User is not valid!"); }
Post[] IMetaWeblog.GetRecentPosts(string blogid, string username, string password, int numberOfPosts) { if (ValidateUser(username, password)) { List<Post> posts = new List<Post>(); VeritasRepository repo = VeritasRepository.GetInstance(); List<BlogEntry> entries = repo.GetRecentEntries(CacheHandler.BlogConfigId, numberOfPosts).ToList(); foreach (var item in entries) { Post pst = new Post(); pst.dateCreated = item.CreateDate; pst.description = item.Short; pst.postid = item.BlogEntryId.ToString(); pst.title = item.Title; pst.userid = item.BlogAuthorId.ToString(); pst.permalink = "http://" + CacheHandler.GetBlogConfig().Host + "/" + item.EntryName; List<string> cats = new List<string>(); foreach (BlogEntryCategory assoc in item.BlogEntryCategories.ToList()) { cats.Add(assoc.BlogCategory.Title); } pst.categories = cats.ToArray(); posts.Add(pst); } return posts.ToArray(); } throw new XmlRpcFaultException(0, "User is not valid!"); }
string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish) { if (ValidateUser(username, password)) { string id = string.Empty; //using (VeritasDataContext con = new VeritasDataContext()) VeritasRepository repo = VeritasRepository.GetInstance(); BlogUser user = repo.GetBlogUserByUserName(CacheHandler.BlogConfigId, username); //Check to see if the entry name exists: //if (repo.DoesEntryTitleExist(post.title, post.title.Replace(";", "-").Replace(" ", "-").Replace(".", "-").Replace("?", "-").Replace("%", "-"), CacheAccessor.GetBlogConfigID())) if (repo.DoesEntryTitleExist(CacheHandler.BlogConfigId, post.title, HttpUtility.HtmlEncode(post.title))) { throw new XmlRpcFaultException(0, "The title you have tried already exists for this blog."); } BlogEntry entry = new BlogEntry(); entry.BlogConfigId = CacheHandler.BlogConfigId; entry.BlogAuthorId = user.BlogUserId; entry.EntryName = EntryTitleLogic.GetEntryNameFromTitle(HttpUtility.HtmlDecode(post.title)); entry.FeedbackCount = 0; entry.PostType = publish ? (int)PostType.Published : (int)PostType.Draft; if (post.dateCreated.Year > 0001) entry.PublishDate = post.dateCreated; else entry.PublishDate = DateTime.Now; //entry.Text = post.description; entry.Text = HighSlideHandler.UpdateLiveWriterImagesWithHighslide(post.description); entry.Title = HttpUtility.HtmlDecode(post.title); entry.LastUpdateDate = DateTime.Now; entry.CreateDate = DateTime.Now; //id = con.SaveBlogEntry(entry).ToString(); repo.Add(entry); repo.Save(); id = entry.BlogEntryId.ToString(); BlogConfig config = repo.GetBlogConfigByBlogConfigId(entry.BlogConfigId); config.PostCount++; repo.Save(); BlogEntryCategory entCat = new BlogEntryCategory(); repo.SaveEntryCategoryAssociation(entry.BlogConfigId, entry.BlogEntryId, post.categories); //Save Blog Entry View var existingViewCount = repo.GetBlogEntryViewCountByEntryId(entry.BlogEntryId); if (existingViewCount == null) { BlogEntryViewCount entryViewCount = new BlogEntryViewCount() { BlogConfigId = entry.BlogConfigId, BlogEntryId = entry.BlogEntryId, WebCount = 0, WebLastUpdated = DateTime.Now }; repo.Add(entryViewCount); repo.Save(); } return id; } throw new XmlRpcFaultException(0, "User is not valid!"); }