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); }
public void WhenPostingNewPostWithoutPublishDateSpecified_AndThereIsNoLastPost_ScheduleItForTomorrowAtNoot() { var rescheduler = new PostSchedulingStrategy(Session, Now); var result = rescheduler.Schedule(); Assert.Equal(Now.AddDays(1).SkipToNextWorkDay().AtNoon(), result); }
public void WhenPostingNewPostWithPublishDateSpecified_AndThereIsNoLastPost_ScheduleItForSpecifiedDate() { var rescheduler = new PostSchedulingStrategy(Session, Now); var scheduleDate = Now.AddHours(1); var result = rescheduler.Schedule(scheduleDate); Assert.Equal(scheduleDate, result); }
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; }
public void WhenPostingNewPostWithoutPublishDateSpecified_AndTheLastPostPublishDateIsAFewDaysAgo_ScheduleItForTomorrowAtNoot() { Session.Store(new Post { PublishAt = Now.AddDays(-3) }); Session.SaveChanges(); var rescheduler = new PostSchedulingStrategy(Session, Now); var result = rescheduler.Schedule(); Assert.Equal(Now.AddDays(1).SkipToNextWorkDay().AtNoon(), result); }
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); }
public void WhenPostingNewPost_DoNotReschedulePublishedPosts() { Session.Store(new Post { PublishAt = Now.AddDays(-3) }); Session.Store(new Post { PublishAt = Now.AddHours(-1) }); Session.SaveChanges(); var rescheduler = new PostSchedulingStrategy(Session, Now); rescheduler.Schedule(); Assert.Empty(Session.Query<Post>().Where(post => post.PublishAt > Now)); }
public void WhenPostingNewPostWithPublishDateSpecified_AndTheLastPostPublishDateIsAFewDaysAgo_ScheduleItForSpecifiedDate() { Session.Store(new Post { PublishAt = Now.AddDays(-3) }); Session.SaveChanges(); var rescheduler = new PostSchedulingStrategy(Session, Now); var scheduleDate = Now.AddHours(1); var result = rescheduler.Schedule(scheduleDate); Assert.Equal(scheduleDate, result); Assert.NotEqual(scheduleDate.AddDays(-2), result); }
public ActionResult Update(PostInput input) { if (!ModelState.IsValid) return View("Edit", input); var post = RavenSession.Load<Post>(input.Id) ?? new Post {CreatedAt = DateTimeOffset.Now}; input.MapPropertiesToInstance(post); // Be able to record the user making the actual post var user = RavenSession.GetCurrentUser(); if (string.IsNullOrEmpty(post.AuthorId)) { post.AuthorId = user.Id; } else { post.LastEditedByUserId = user.Id; post.LastEditedAt = DateTimeOffset.Now; } if (post.PublishAt == DateTimeOffset.MinValue) { var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now); post.PublishAt = postScheduleringStrategy.Schedule(); } // Actually save the post now RavenSession.Store(post); if (input.IsNewPost()) { // Create the post comments object and link between it and the post var comments = new PostComments { Comments = new List<PostComments.Comment>(), Spam = new List<PostComments.Comment>(), Post = new PostComments.PostReference { Id = post.Id, PublishAt = post.PublishAt, } }; RavenSession.Store(comments); post.CommentsId = comments.Id; } return RedirectToAction("Details", new {Id = post.MapTo<PostReference>().DomainId}); }
public ActionResult Add(PostInput input) { if (!ModelState.IsValid) return View("Edit", input); // Be able to record the user making the actual post var user = RavenSession.GetCurrentUser(); // Create the post comments object and link between it and the post var comments = new PostComments { Comments = new List<PostComments.Comment>(), Spam = new List<PostComments.Comment>() }; RavenSession.Store(comments); // Create new post object var post = new Post { Tags = TagsResolver.ResolveTagsInput(input.Tags), PublishAt = input.PublishAt, AllowComments = input.AllowComments, AuthorId = user.Id, LastEditedByUserId = user.Id, LastEditedAt = DateTimeOffset.Now, CommentsId = comments.Id, ContentType = input.ContentType, Body = input.Body, CreatedAt = DateTimeOffset.Now, Title = input.Title, }; if (post.PublishAt == DateTimeOffset.MinValue) { var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now); post.PublishAt = postScheduleringStrategy.Schedule(); } // Actually save the post now RavenSession.Store(post); comments.Post = new PostComments.PostReference { Id = post.Id, PublishAt = post.PublishAt, }; return RedirectToAction("Details", new { id = post.Id.ToIntId() }); }
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); }
public void UpdatePublishDateOfExistintPost_WillUpdateTheDateAndTimeCorrectly() { Session.Store(new Post { PublishAt = Now.AddDays(-3) }); Session.Store(new Post { PublishAt = Now.AddHours(-1) }); Session.Store(new Post { PublishAt = Now.AddHours(12) }); Session.SaveChanges(); var lastPost = Session.Query<Post>() .OrderByDescending(post => post.PublishAt) .First(); Assert.Equal(Now.AddHours(12), lastPost.PublishAt); var rescheduler = new PostSchedulingStrategy(Session, Now); lastPost.PublishAt = rescheduler.Schedule(Now.AddHours(6)); Session.SaveChanges(); Assert.Equal(Now.AddHours(6), lastPost.PublishAt); }
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; }
public ActionResult Update(TempInput sendInfo) { //var post = RavenSession.Load<Post>(input.Id) ?? new Post { CreatedAt = DateTimeOffset.Now };//Post is an empty tool here //////////////// sendInfo.Id = "0"; var post = RavenSession.Load<Post>(sendInfo.Id) ?? new Post { CreatedAt = DateTimeOffset.Now };//Post is an empty tool here //input.MapPropertiesToInstance(post);//Entering data /////////////////////// post.Title = sendInfo.Title; if (sendInfo.AllowComments == "on") post.AllowComments = true; else post.AllowComments = false; post.Body = sendInfo.Body; post.CreatedAt = DateTimeOffset.Now; //Convert PublishAt (string) into dateTime string mm = sendInfo.PublishAt.Substring(0, 2); int mmInt = int.Parse(mm); string dd = sendInfo.PublishAt.Substring(3,2); int ddInt = int.Parse(dd); string yy = sendInfo.PublishAt.Substring(6, 4); int yyInt = int.Parse(yy); // Convert into date DateTime TempDate=new DateTime(yyInt,mmInt,ddInt); // Convert into DateTimeOffset DateTimeOffset TempDateOffSet=new DateTimeOffset(TempDate); // Entering the date into post post.PublishAt = TempDateOffSet; // Entering the tag string tempTag = sendInfo.Tags; ICollection<string> t=new Collection<string>(); t.Add(tempTag); post.Tags.Add(tempTag); //if (!ModelState.IsValid) //////////////////// // return View("Edit", input); ////////////////// // Be able to record the user making the actual post var user = RavenSession.GetCurrentUser(); if (string.IsNullOrEmpty(post.AuthorId)) { post.AuthorId = user.Id; } else { post.LastEditedByUserId = user.Id; post.LastEditedAt = DateTimeOffset.Now; } if (post.PublishAt <= DateTimeOffset.Now) { var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now); post.PublishAt = postScheduleringStrategy.Schedule(); post.PublishAt = DateTimeOffset.Now; post.CreatedAt = DateTimeOffset.Now; } // Actually save the post now RavenSession.Store(post); //if (input.IsNewPost()) ////////////////////// //{ // Create the post comments object and link between it and the post var comments = new PostComments { Comments = new List<PostComments.Comment>(), Spam = new List<PostComments.Comment>(), Post = new PostComments.PostReference { Id = post.Id, PublishAt = post.PublishAt, } }; RavenSession.Store(comments); post.CommentsId = comments.Id; //} //////////////// return RedirectToAction("Details", new { Id = post.MapTo<PostReference>().DomainId }); }