public string AddPost(string blogid, string username, string password, Post post, bool publish) { var entry = CreateUpdatePost(username, password, "-1", post, publish); if (entry != null) return entry.Id.ToString(); throw new XmlRpcFaultException(0, "User is not valid!"); }
public bool UpdatePost(string postid, string username, string password, Post post, bool publish) { var entry = CreateUpdatePost(username, password, postid, post, publish); if (entry != null) return true; throw new XmlRpcFaultException(0, "User is not valid!"); }
private Entry CreateUpdatePost(string username, string password, string postid, Post post, bool publish) { if (ValidateUser(username, password)) { using (var transaction = session.BeginTransaction(IsolationLevel.Serializable)) { var author = authenticator.GetName(); var entry = repository.Get<Entry>(Int32.Parse(postid)); if (entry == null) { entry = new Entry { Author = author }; repository.Add(entry); } entry.Name = post.permalink; entry.Title = post.title ?? string.Empty; entry.Summary = post.mt_excerpt ?? string.Empty; entry.MetaTitle = post.title; entry.Published = (post.dateCreated < DateTime.Today.AddYears(10) ? DateTime.Today : post.dateCreated).ToUniversalTime(); entry.Status = publish ? EntryStatus.PublicBlog : EntryStatus.Private; var revision = entry.Revise(); revision.Author = author; revision.Body = post.description; revision.Reason = "API"; revision.Format = Formats.Html; if (string.IsNullOrWhiteSpace(entry.Name)) entry.Name = post.title.Replace(" ", "-"); // support for slug if (!string.IsNullOrEmpty(post.wp_slug)) entry.Name = post.wp_slug; entry.MetaDescription = entry.Summary; var editTags = post.categories; var toDelete = entry.Tags.Where(t => !editTags.Contains(t.Name)).ToList(); var toAdd = editTags.Where(t => !entry.Tags.Any(tag=>tag.Name == t)).ToList(); foreach (var tag in toDelete) tag.Remove(entry); foreach (var tag in toAdd) { var existingTag = repository.FindFirstOrDefault(new SearchTagsByNameQuery(tag)); if (existingTag == null) { existingTag = new Tag { Name = tag }; repository.Add(existingTag); } existingTag.Add(entry); } session.Flush(); transaction.Commit(); return entry; } } return null; }