public ActionResult Update(PostInput input) { if (!ModelState.IsValid) { return(View("Edit", new EditPostViewModel { Input = input })); } var post = Session.Load <Post>(input.Id) ?? new Post(); input.MapPropertiesToInstance(post); var user = Session.GetCurrentUser(); if (string.IsNullOrEmpty(post.AuthorId)) { post.AuthorId = user.Id; } else { post.LastEditedByUserId = user.Id; post.LastEditedAt = DateTimeOffset.Now; } Session.Store(post); var postReference = post.MapTo <PostReference>(); return(RedirectToAction("Details", new { Id = postReference.DomainId, postReference.Slug })); }
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); // Once the Comments have been saved, update and save the post post.CommentsId = comments.Id; RavenSession.Store(post); } return(RedirectToAction("Details", new { Id = post.MapTo <PostReference>().DomainId })); }
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 Edit(PostInput input, int id) { if (!ModelState.IsValid) return View("Edit", input); var post = RavenSession.Load<Post>(id) ?? new Post(); input.MapPropertiesToInstance(post); var user = RavenSession.GetCurrentUser(); if (string.IsNullOrEmpty(post.AuthorId)) { post.AuthorId = user.Id; } else { post.LastEditedByUserId = user.Id; post.LastEditedAt = DateTimeOffset.Now; } RavenSession.Store(post); var postReference = post.MapTo<PostReference>(); return RedirectToAction("Details", new { Id = postReference.DomainId, postReference.Slug}); }