public ActionResult CreatePostGet() { _ops = new MVCBlogOps(); BlogPostVM blogPostVM = new BlogPostVM(); _res = new Response(); _res = _ops.GetAllCategoriesFromRepo(); blogPostVM.CreateCategoriesList(_res.Categories); return View(blogPostVM); }
public ActionResult CreatePostPost(BlogPostVM blogPostVM) { _ops = new MVCBlogOps(); var blogPost = new BlogPost(); var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())); var user = userManager.FindById(User.Identity.GetUserId()); if (User.IsInRole("Admin")) { blogPostVM.blogPost.Status = 1; // 1 is Approved blogPost.Status = blogPostVM.blogPost.Status; } else { blogPostVM.blogPost.Status = 2; // 2 is Unapproved blogPost.Status = blogPostVM.blogPost.Status; } blogPost.User.UserID = user.Id; blogPost.Title = blogPostVM.blogPost.Title; blogPost.Mce.Body = blogPostVM.blogPost.Mce.Body; blogPost.Category.CategoryID = blogPostVM.category.CategoryID; if (blogPostVM.tags == null) { HashTag hashTag = new HashTag(); hashTag.HashTagName = "#freshfoods"; blogPost.HashTags.Add(hashTag); } else { foreach (var item in blogPostVM.tags) { HashTag hashTag = new HashTag(); hashTag.HashTagName = item; blogPost.HashTags.Add(hashTag); } } _ops.SaveBlogPostToRepo(blogPost); return RedirectToAction("Index", "Home"); }
public ActionResult EditPostGet(int id) { _res = new Response(); _ops = new MVCBlogOps(); BlogPostVM blogPostVM = new BlogPostVM(); _res = _ops.GetBlogPostByIDFromRepo(id); blogPostVM.blogPost = _res.BlogPost; blogPostVM.blogPost.HashTags = _res.BlogPost.HashTags; blogPostVM.blogPost.Mce.Body = _res.BlogPost.Body; blogPostVM.blogPost.Category = _res.BlogPost.Category; blogPostVM.CreateCategoriesList(_ops.GetAllCategoriesFromRepo().Categories); _ops.ArchiveBlogPostToRepo(blogPostVM.blogPost);// return View(blogPostVM); }