Esempio n. 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);
        }
Esempio n. 2
0
 public ActionResult EditPost(int postId)
 {
     PostViewModel vm = new PostViewModel();
     var post = postService.GetPostById(postId);
     if (post != null)
     {
         vm.PostId = post.PostId;
         vm.Title = post.Title;
         vm.Description = post.Description;
         vm.Category = post.Category.Name;
         vm.Summery = post.Summery;
         vm.IsPublished = vm.IsPublished;
         vm.Tags = post.Tags != null ? string.Join(",", post.Tags.Select(a => a.Name).ToArray()) : "";
     }
     vm.Categories = PopulateCategories();
     return View(vm);
 }
Esempio n. 3
0
 public ActionResult AddPost()
 {
     PostViewModel vm = new PostViewModel();
     vm.Categories = PopulateCategories();
     return View(vm);
 }
Esempio n. 4
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);
 }