예제 #1
0
        Post IMetaWeblog.GetPost(string postid, string username, string password)
        {
            validate_user(username, password);

            using (var session = _store.OpenSession())
            {
                var thePost = session.Load<Models.Post>(postid);
                if (thePost == null || thePost.IsDeleted)
                {
                    _log.Trace("Post id: {0} does not exists, or has been deleted", postid);
                    throw new XmlRpcFaultException(0, "Post does not exists");
                }

                var toReturn = new Post
                {
                    wp_slug = SlugConverter.TitleToSlug(thePost.Title),
                    description = thePost.Content,
                    dateCreated = thePost.PublishAt.DateTime,
                    categories = thePost.Categories.Select(x => x.Title).ToArray(),
                    mt_keywords = string.Join(", ", thePost.Tags.Select(x => x.Title).ToArray()),
                    title = thePost.Title,
                    postid = thePost.Id,
                };

                _log.Trace("Returning psotid: {0}, Post: {1}", postid, toReturn.ToJson());

                return toReturn;
            }
        }
예제 #2
0
        bool IMetaWeblog.UpdatePost(string postid, string username, string password, Post post, bool publish)
        {
            _log.Trace("Updating post. postid: {0}, Publish: {1}, Post: {2}", postid, publish, post.ToJson());

            using (var session = _store.OpenSession())
            {
                var user = validate_user(username, password);
                var postToEdit = session
                    .Include<Models.Post>(x => x.CommentsId)
                    .Load(postid);

                if (postToEdit == null)
                {
                    throw new XmlRpcFaultException(0, "Post does not exists");
                }

                if (postToEdit.AuthorId.IsNullOrWhiteSpace())
                {
                    postToEdit.AuthorId = user.Id;
                }

                    //postToEdit.AuthorId = user.Id;
                var currentDate = ApplicationTime.Current;
                postToEdit.Modified = currentDate;

                postToEdit.Content = post.description;

                if (post.dateCreated.HasValue
                    && post.dateCreated.Value != postToEdit.PublishAt.DateTime)
                {
                    postToEdit.PublishAt = _schedule.Schedule(new DateTimeOffset(post.dateCreated.Value));
                    session.Load<PostComments>(postToEdit.CommentsId).Post.Published = postToEdit.PublishAt;
                }

                var cat = post.categories == null ? new List<string>() : post.categories.ToList();
                var key = post.mt_keywords.IsNullOrWhiteSpace() ? new List<string>() : post.mt_keywords.Split(',').ToList();

                postToEdit.Categories = cat.Select(x => new Models.Post.SlugItem
                {
                    Title = x
                }).ToList();

                postToEdit.Tags = key.Select(x => new Models.Post.SlugItem
                {
                    Title = x
                }).ToList();

                postToEdit.Title = HttpUtility.HtmlDecode(post.title);
                postToEdit.Slug = SlugConverter.TitleToSlug(postToEdit.Title);

                // only send notification when post is published!
                if (currentDate < postToEdit.PublishAt)
                {
                    try
                    {
                        _notification.Send(postToEdit
                            , new Uri(Url.AbsoluteAction("Details", "PostDetails", postToEdit.ToRouteData())));
                        postToEdit.NotificationSend = true;
                    }
                    catch (Exception ex)
                    {
                        postToEdit.NotificationSend = false;
                    }
                }

                session.SaveChanges();
            }

            return true;
        }
예제 #3
0
        string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
        {
            _log.Trace("Adding new blog post. Blogid: {0}, Publish: {1}, Post: {2}", blogid, publish, post.ToJson());

            Models.Post newPost;
            using (var session = _store.OpenSession())
            {
                var user = validate_user(username, password);
                var comments = new PostComments
                {
                    Comments = new List<PostComments.Comment>(),
                    Spam = new List<PostComments.Comment>()
                };
                session.Store(comments);

                var currentDate = ApplicationTime.Current;
                var publishDate = post.dateCreated  == null ? currentDate : _schedule.Schedule(new DateTimeOffset(post.dateCreated.Value));

                var cat = post.categories == null ? new List<string>() : post.categories.ToList();
                var key = post.mt_keywords.IsNullOrWhiteSpace() ? new List<string>() : post.mt_keywords.Split(',').ToList();

                newPost = new Models.Post
                {
                    AuthorId = user.Id,
                    Content = post.description,
                    CommentsId = comments.Id,
                    Created = currentDate,
                    Modified = currentDate,
                    PublishAt = publishDate,
                    Categories = cat.Select(x => new Models.Post.SlugItem { Title = x }).ToList(),
                    Tags = key.Select(x => new Models.Post.SlugItem { Title = x }).ToList(),
                    Title = HttpUtility.HtmlDecode(post.title),
                    CommentsCount = 0,
                    AllowComments = true,
                };

                // only send notification when post is published!
                if (publishDate == currentDate)
                {
                    try
                    {
                        _notification.Send(newPost
                            , new Uri(Url.AbsoluteAction("Details", "PostDetails", newPost.ToRouteData())));
                        newPost.NotificationSend = true;
                    }
                    catch (Exception ex)
                    {
                        newPost.NotificationSend = false;
                    }
                }

                session.Store(newPost);
                comments.Post = new PostComments.PostReference
                {
                    Id = newPost.Id,
                    Published = publishDate,
                    Slug = newPost.Slug
                };

                session.SaveChanges();
            }

            return newPost.Id;
        }