public ActionResult Edit(EditPostPageViewModel currentPage, int year, string slug) { //auth only if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Admin")); } //redirect on no slug if (string.IsNullOrWhiteSpace(slug)) { return(RedirectToAction("Index", "Blog")); } //try find the slug directly var originalPost = StorageHelper.ReadPost(year, slug, true); if (originalPost != null) { currentPage.Slug = originalPost.Slug; currentPage.Title = originalPost.Title; currentPage.PostedTime = originalPost.PostedTime; currentPage.BodyMarkdown = originalPost.BodyMarkdown; currentPage.ReadTime = originalPost.ReadTime; currentPage.Categories = originalPost.Categories; currentPage.DontIndexPost = originalPost.DontIndexPost; currentPage.MetaDescPost = originalPost.MetaDescPost; return(View("Edit", currentPage)); } return(HttpNotFound()); }
public ActionResult Edit(EditPostPageViewModel currentPage, int id) { //auth only if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Admin")); } //try find the post var originalPost = StorageHelper.ReadPost(id, true); if (originalPost != null) { currentPage.Title = originalPost.Title; currentPage.PostedTime = originalPost.PostedTime; currentPage.BodyMarkdown = originalPost.BodyMarkdown; currentPage.Id = originalPost.Id; currentPage.EmbedUrl = originalPost.EmbedUrl; currentPage.DontIndexPost = originalPost.DontIndexEpisode; currentPage.MetaDescPost = originalPost.MetaDescEpisode; return(View("Edit", currentPage)); } return(HttpNotFound()); }
public ActionResult EditPost(DialoguePage page) { using (UnitOfWorkManager.NewUnitOfWork()) { // Got to get a lot of things here as we have to check permissions // Get the post var id = Request["id"]; if (string.IsNullOrEmpty(id)) { return(ErrorToHomePage(Lang("Errors.GenericMessage"))); } var post = ServiceFactory.PostService.Get(new Guid(id)); // Get the topic var topic = post.Topic; var category = ServiceFactory.CategoryService.Get(topic.CategoryId); // get the users permissions var permissions = ServiceFactory.PermissionService.GetPermissions(category, _membersGroup); if (post.MemberId == CurrentMember.Id || permissions[AppConstants.PermissionModerate].IsTicked) { var viewModel = new EditPostViewModel { Content = Server.HtmlDecode(post.PostContent), Id = post.Id, Permissions = permissions }; // Now check if this is a topic starter, if so add the rest of the field if (post.IsTopicStarter) { viewModel.Category = topic.CategoryId; viewModel.IsLocked = topic.IsLocked; viewModel.IsSticky = topic.IsSticky; viewModel.IsTopicStarter = post.IsTopicStarter; viewModel.Name = topic.Name; viewModel.Categories = ServiceFactory.CategoryService.GetAllowedCategories(_membersGroup).ToList(); if (topic.Poll != null && topic.Poll.PollAnswers.Any()) { // Has a poll so add it to the view model viewModel.PollAnswers = topic.Poll.PollAnswers; } } var pageViewModel = new EditPostPageViewModel(page) { EditPostViewModel = viewModel, PageTitle = Lang("Post.EditPostPageTitle") }; return(View(PathHelper.GetThemeViewPath("EditPost"), pageViewModel)); } return(NoPermission(topic)); } }
public ActionResult SubmitEdit(EditPostPageViewModel currentPage) { //make sure we can do it if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Admin")); } if (ModelState.IsValid) { //get the original from file with markdown for image parsing var originalPost = StorageHelper.ReadPost(currentPage.PostedTime.Year, currentPage.Slug, true); if (originalPost != null) { //first we delete abandoned images PostHelper.ProcessRemovedImages(originalPost.BodyMarkdown, currentPage.BodyMarkdown); //NOTICE the html markdown switcharoo //update with the fields we allow changing originalPost.BodyHtml = CommonMarkConverter.Convert(currentPage.BodyMarkdown); originalPost.BodyMarkdown = currentPage.BodyMarkdown; originalPost.DontIndexPost = currentPage.DontIndexPost; originalPost.MetaDescPost = currentPage.MetaDescPost; originalPost.Title = currentPage.Title; originalPost.Categories = currentPage.Categories; //PS get the new read time after the new body has been populated originalPost.ReadTime = PostHelper.GetReadTime(ref originalPost); //save the post (will update the cache as well) StorageHelper.SavePost(originalPost); return(RedirectToAction("Index", "Post", new { year = originalPost.PostedTime.Year, slug = originalPost.Slug })); } } //not valid, return return(View("Edit", currentPage)); }
public ActionResult SubmitEdit(EditPostPageViewModel currentPage) { //make sure we can do it if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Admin")); } if (ModelState.IsValid) { //get the original from file with markdown for image parsing var originalPost = StorageHelper.ReadPost(currentPage.Id, true); if (originalPost != null) { //first we delete abandoned images PostHelper.ProcessRemovedImages(originalPost.BodyMarkdown, currentPage.BodyMarkdown); //NOTICE the html markdown switcharoo //update with the fields we allow changing originalPost.BodyHtml = CommonMarkConverter.Convert(currentPage.BodyMarkdown); originalPost.BodyMarkdown = currentPage.BodyMarkdown; originalPost.DontIndexEpisode = currentPage.DontIndexPost; originalPost.MetaDescEpisode = currentPage.MetaDescPost; originalPost.Title = currentPage.Title; originalPost.EmbedUrl = currentPage.EmbedUrl; //save the post (will update the cache as well) StorageHelper.SavePost(originalPost); return(RedirectToAction("Index", "Episode", new { id = originalPost.Id })); } } //not valid, return return(View("Edit", currentPage)); }