public ActionResult AddPost(PostViewModel vm) { if (ModelState.IsValid) { var post = new Post(); post.Title = vm.Title; post.Description = vm.Description; post.PublishedDate = DateTime.Now; post.Summery = vm.Summery; post.IsPublished = vm.IsPublished; post.Category = categoryService.GetCategory(int.Parse(vm.Category)); post.Tags = tagService.GetRelevantTag(vm.Tags); var user = userService.GetUserById(User.Identity.GetUserId()); post.User = userService.GetUserById(User.Identity.GetUserId()); postService.AddPost(post); postService.SaveChanges(); ViewBag.Message = "Your Post Succesfully posted"; } vm.Categories = PopulateCategories(); return View(vm); }
public ActionResult EditPost(PostViewModel vm) { if (ModelState.IsValid) { var post = new Post() { PostId = vm.PostId, Title = vm.Title, Summery = vm.Summery, Description = vm.Description, PublishedDate = DateTime.Now, IsPublished = vm.IsPublished, Category = categoryService.GetCategory(int.Parse(vm.Category)) }; postService.UpdatePost(post); postService.SaveChanges(); } vm.Categories = PopulateCategories(); return View(vm); }
public void UpdatePost(Post post) { this.postRepository.UpdatePost(post); }
public ShowPostViewModel() { CommentViewModel = new CommentViewModel(); Post = new Post(); }
public void AddPost(Post p) { this.postRepository.AddPost(p); }