public ActionResult Edit(int id, PostEditModel model) { ViewBag.Title = "Edit"; if (ModelState.IsValid) { var post = _postRepository.PostsForBlog(CurrentBlog.Id).Single(p => p.Id == id); var pm = PostModification.GetUnmodifiedPostModification(); pm.PostId = id; if (model.Body != post.Body && model.Body != post.DraftBody) { pm.BodyModified = true; pm.NewBody = model.Body; } if (model.Description != post.Description && model.Description != post.DraftDescription) { pm.DescriptionModified = true; pm.NewDescription = model.Description; } if (model.CanonicalUrl != post.Canonical) { pm.CannonicalModified = true; pm.NewCannonical = model.CanonicalUrl; } if (model.Title != post.Title && model.Title != post.DraftTitle) { pm.TitleModified = true; pm.NewTitle = model.Title; } if (pm.HasModifications()) { _postModificationRepository.Create(pm); post.DraftTitle = model.Title; post.DraftDescription = model.Description; post.DraftBody = model.Body; post.Canonical = model.Reposted ? model.CanonicalUrl : "/" + post.Path; _postRepository.Update(post); } return(RedirectToAction("Index", "Dashboard")); } return(View(model)); }
public ActionResult ConfirmPublish(int id, ConfirmPublishModel model) { var post = _postRepository.PostsForBlog(CurrentBlog.Id).Single(p => p.Id == id); if (post == null) { throw new HttpException((int)HttpStatusCode.NotFound, "The specified post was not found"); } if (ModelState.IsValid) { //We want to update the published date if we are publishing for the first time if (post.Status == PostStatus.Draft) { post.Posted = _dateTime.Now; } post.Status = PostStatus.Published; post.Title = post.DraftTitle; post.Description = post.DraftDescription; post.Body = post.DraftBody; post.DraftBody = null; post.DraftDescription = null; post.DraftTitle = null; var pm = PostModification.GetUnmodifiedPostModification(_dateTime.Now); pm.PostId = id; pm.StatusModified = true; pm.NewStatus = PostStatus.Published; _postModificationRepository.Create(pm); _postRepository.Update(post); return(Json(new { success = true })); } return(PartialView("ConfirmPublishModal", model)); }