예제 #1
0
        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);
        }
예제 #2
0
 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);
 }
예제 #3
0
 public void UpdatePost(Post post)
 {
     this.postRepository.UpdatePost(post);
 }
예제 #4
0
 public ShowPostViewModel()
 {
     CommentViewModel = new CommentViewModel();
     Post = new Post();
 }
예제 #5
0
 public void AddPost(Post p)
 {
     this.postRepository.AddPost(p);
 }