Ejemplo n.º 1
0
        string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
        {
            var user = ValidateUser(username, password);
            var comments = new PostComments();
            session.Store(comments);

            var publishDate = post.dateCreated == null
                                ? postScheduleringStrategy.Schedule()
                                : postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));

            var newPost = new Models.Post
            {
                AuthorId = user.Id,
                Body = post.description,
                CommentsId = comments.Id,
                CreatedAt = DateTimeOffset.Now,
                SkipAutoReschedule = post.dateCreated != null,
                PublishAt = publishDate,
                Tags = post.categories,
                Title = post.title,
                CommentsCount = 0,
            };
            session.Store(newPost);
            session.SaveChanges();

            return newPost.Id;
        }
Ejemplo n.º 2
0
        string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
        {
            var user     = ValidateUser(username, password);
            var comments = new PostComments();

            session.Store(comments);

            var publishDate = post.dateCreated == null
                                ? postScheduleringStrategy.Schedule()
                                : postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));

            var newPost = new Models.Post
            {
                AuthorId           = user.Id,
                Body               = post.description,
                CommentsId         = comments.Id,
                CreatedAt          = DateTimeOffset.Now,
                SkipAutoReschedule = post.dateCreated != null,
                PublishAt          = publishDate,
                Tags               = post.categories,
                Title              = post.title,
                CommentsCount      = 0,
            };

            session.Store(newPost);
            session.SaveChanges();

            return(newPost.Id);
        }
Ejemplo n.º 3
0
        bool IMetaWeblog.UpdatePost(string postid, string username, string password, Post post, bool publish)
        {
            var user       = ValidateUser(username, password);
            var postToEdit = session.Load <Models.Post>(postid);

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

            if (string.IsNullOrEmpty(postToEdit.AuthorId))
            {
                postToEdit.AuthorId = user.Id;
            }
            else
            {
                postToEdit.LastEditedByUserId = user.Id;
                postToEdit.LastEditedAt       = DateTimeOffset.Now;
            }

            postToEdit.Body = post.description;
            if (
                // don't bother moving things if we are already talking about something that is fixed
                postToEdit.SkipAutoReschedule &&
                // if we haven't modified it, or if we modified to the same value, we can ignore this
                post.dateCreated != null &&
                post.dateCreated.Value != postToEdit.PublishAt.DateTime
                )
            {
                // schedule all the future posts up
                postToEdit.PublishAt = postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));
            }
            postToEdit.Tags  = post.categories;
            postToEdit.Title = post.title;

            {
                // schedule all the future posts up
                postToEdit.PublishAt = postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));
            }
            postToEdit.Tags  = post.categories;
            postToEdit.Title = post.title;

            session.SaveChanges();

            return(true);
        }
Ejemplo n.º 4
0
		string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
		{
			Models.Post newPost;
			using (var session = MvcApplication.DocumentStore.OpenSession())
			{
				var user = ValidateUser(username, password);
				var comments = new PostComments
								{
									Comments = new List<PostComments.Comment>(),
									Spam = new List<PostComments.Comment>()
								};
				session.Store(comments);

				var postScheduleringStrategy = new PostSchedulingStrategy(session, DateTimeOffset.Now);
				var publishDate = post.dateCreated == null
									? postScheduleringStrategy.Schedule()
									: postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));

				newPost = new Models.Post
								{
									AuthorId = user.Id,
									Body = post.description,
									CommentsId = comments.Id,
									CreatedAt = DateTimeOffset.Now,
									SkipAutoReschedule = post.dateCreated != null,
									PublishAt = publishDate,
									Tags = post.categories,
									Title = post.title,
									CommentsCount = 0,
									AllowComments = true,
								};
				session.Store(newPost);
				comments.Post = new PostComments.PostReference
									{
										Id = newPost.Id,
										PublishAt = publishDate
									};

				session.SaveChanges();
			}

			return newPost.Id;
		}
Ejemplo n.º 5
0
        string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
        {
            Models.Post newPost;
            using (var session = MvcApplication.DocumentStore.OpenSession())
            {
                var user     = ValidateUser(username, password);
                var comments = new PostComments
                {
                    Comments = new List <PostComments.Comment>(),
                    Spam     = new List <PostComments.Comment>()
                };
                session.Store(comments);

                var postScheduleringStrategy = new PostSchedulingStrategy(session, DateTimeOffset.Now);
                var publishDate = post.dateCreated == null
                                                                        ? postScheduleringStrategy.Schedule()
                                                                        : postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));

                newPost = new Models.Post
                {
                    AuthorId           = user.Id,
                    Body               = post.description,
                    CommentsId         = comments.Id,
                    CreatedAt          = DateTimeOffset.Now,
                    SkipAutoReschedule = post.dateCreated != null,
                    PublishAt          = publishDate,
                    Tags               = post.categories,
                    Title              = post.title,
                    CommentsCount      = 0,
                    AllowComments      = true,
                };
                session.Store(newPost);
                comments.Post = new PostComments.PostReference
                {
                    Id        = newPost.Id,
                    PublishAt = publishDate
                };

                session.SaveChanges();
            }

            return(newPost.Id);
        }
Ejemplo n.º 6
0
		bool IMetaWeblog.UpdatePost(string postid, string username, string password, Post post, bool publish)
		{
			using (var session = MvcApplication.DocumentStore.OpenSession())
			{
				var user = ValidateUser(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 (string.IsNullOrEmpty(postToEdit.AuthorId))
					postToEdit.AuthorId = user.Id;
				else
				{
					postToEdit.LastEditedByUserId = user.Id;
					postToEdit.LastEditedAt = DateTimeOffset.Now;
				}

				postToEdit.Body = post.description;
				if (
					// don't bother moving things if we are already talking about something that is fixed
					postToEdit.SkipAutoReschedule &&
					// if we haven't modified it, or if we modified to the same value, we can ignore this
					post.dateCreated != null &&
					post.dateCreated.Value != postToEdit.PublishAt.DateTime
					)
				{
					// schedule all the future posts up 
					var postScheduleringStrategy = new PostSchedulingStrategy(session, DateTimeOffset.Now);
					postToEdit.PublishAt = postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));
					session.Load<PostComments>(postToEdit.CommentsId).Post.PublishAt = postToEdit.PublishAt;
				}
				postToEdit.Tags = post.categories;
				postToEdit.Title = post.title;

				session.SaveChanges();
			}

			return true;
		}