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 string AddPost(string blogid, string username, string password, Post post, bool publish) { Exception exception; if (!IsValidUser(username, password, out exception)) { throw exception; } var entry = CreateUpdatePost("-1", post, publish); if (entry != null) { return entry.Id.ToString(CultureInfo.InvariantCulture); } return null; }
private Entry CreateUpdatePost(string postid, Post post, bool publish) { using (var transaction = session.BeginTransaction(IsolationLevel.Serializable)) { var isOldPost = true; var author = authenticator.GetName(); var entry = repository.Get<Entry>(Int32.Parse(postid)); if (entry == null) { entry = new Entry { Author = author }; isOldPost = false; } entry.Name = post.permalink; entry.Title = post.title ?? string.Empty; entry.Summary = string.IsNullOrEmpty(post.mt_excerpt) ? entry.Summary : post.mt_excerpt; 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 = string.Equals(post.format, Formats.Markdown, StringComparison.InvariantCultureIgnoreCase) ? Formats.Markdown : 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.MetaDescription ?? post.mt_excerpt; var editTags = post.categories; var toDelete = entry.Tags.Where(t => !editTags.Contains(t.Name)).ToList(); var toAdd = editTags.Where(t => entry.Tags.All(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); } //Does it need to be added? if (!isOldPost) { repository.Add(entry); } session.Flush(); transaction.Commit(); return entry; } }
public bool UpdatePost(string postid, string username, string password, Post post, bool publish) { Exception exception; if (!IsValidUser(username, password, out exception)) { throw exception; } var entry = CreateUpdatePost(postid, post, publish); if (entry != null) return true; throw new XmlRpcFaultException(0, "User is not valid!"); }