public ActionResult Edit(int id) { var userId = this.User.Identity.GetUserId(); var post = this.writerPosts .GetPostById(id) .FirstOrDefault(); if (userId == post.AuthorId) { var editPostViewModel = new WriterEditPostViewModel { Title = post.Title, Content = post.Content, CategoryId = post.CategoryId, UrlVideo = post.UrlVideo }; ViewBag.SelectedItem = populator.GetSelectedCategories(); return(View(editPostViewModel)); } this.TempData["Message"] = string.Format(GlobalConstants.FailMessage, "! This not your post!"); return(RedirectToAction("Index")); }
public ActionResult Edit(int id, WriterEditPostViewModel viewModel) { if (viewModel != null && ModelState.IsValid) { var userId = this.User.Identity.GetUserId(); var post = this.writerPosts.GetPostById(id).FirstOrDefault(); if (userId == post.AuthorId) { this.writerPosts.Edit(post, viewModel); this.TempData["Message"] = string.Format(GlobalConstants.SuccessMessage, " Edited Post."); return(this.RedirectToAction("Index", "WriterPosts", new { area = "Writer" })); } this.TempData["Message"] = string.Format(GlobalConstants.FailMessage, "! This not your post!"); return(this.RedirectToAction("Index")); } this.TempData["Message"] = string.Format(GlobalConstants.FailMessage, " Edited Post."); ViewBag.SelectedItem = populator.GetSelectedCategories(); return(this.View(viewModel)); }
public void Edit(Post post, WriterEditPostViewModel viewModel) { post.Title = viewModel.Title; post.Content = this.sanitizer.Sanitize(viewModel.Content); post.CategoryId = viewModel.CategoryId; var image = WebImage.GetImageFromRequest(); if (image != null) { var sliderImage = image.Clone(); var thumbnailImage = image.Clone(); base.UpdatedSliderPostCoverImage(post, viewModel, sliderImage); base.UpdatedThumbnailPostCoverImage(post, viewModel, thumbnailImage); } post.Status = Status.EditedWaitingAppoval; Data.Posts.Update(post); Data.SaveChanges(); }