public ActionResult SetPublishDate() { var model = new List <PublishDateViewModel>(); var bRepo = BlogPostRepoManagerFactory.Create(); var blogResp = bRepo.GetAllBlogs(); if (blogResp.Success) { var blogList = bRepo.GetAllBlogs().BlogPosts; foreach (var blog in blogList) { model.Add(new PublishDateViewModel() { BlogPostId = blog.BlogPostId, Blog = blog.Blog, Title = blog.Title, Approved = blog.Approved, CatagoryId = blog.CatagoryId, PublishDate = blog.PublishDate, DateAdded = blog.DateAdded, Id = blog.Id, HeaderImage = blog.HeaderImage, BlogPostHashTags = blog.BlogPostHashTags, UserName = blog.UserName }); } return(View(model)); } else { return(RedirectToAction("Blogs")); } }
public ActionResult SetPublishDate(int blogPostId, DateTime date) { var repo = BlogPostRepoManagerFactory.Create(); repo.SetPublishDate(blogPostId, date); return(RedirectToAction("SetPublishDate", "Admin")); }
public ActionResult BlogPost(int blogId) { var blogMgr = BlogPostRepoManagerFactory.Create(); var blogResponse = blogMgr.GetBlogById(blogId); var model = new SingleBlogPostViewModel(); var hashMgr = HashTagManagerFactory.Create(); var cateMgr = CategoryRepoManagerFactory.Create(); if (blogResponse.Success) { model.BlogPost = blogResponse.BlogPost; var hashTagResponse = hashMgr.GetHashTagsForBlog(blogResponse.BlogPost.BlogPostId); if (hashTagResponse.Success) { model.HashTags = hashTagResponse.HashTags; } } var cates = cateMgr.GetAllCategories(); if (cates.Success) { model.Catagories = cates.Catagories; } return(View(model)); }
public ActionResult ApproveBlog(int id) { var repo = BlogPostRepoManagerFactory.Create(); repo.ApproveBlog(id); repo.SetPublishDate(id, DateTime.Now); return(RedirectToAction("Blogs")); }
public ActionResult DeleteBlog(int blogPostId) { var repo = BlogPostRepoManagerFactory.Create(); repo.RemoveBlog(blogPostId); return(RedirectToAction("Blogs")); }
public ActionResult BlogsByCatagory(int id) { BlogPostRepoManager manager = BlogPostRepoManagerFactory.Create(); if (!manager.GetBlogsByCatagory(id).Success) { return(RedirectToAction("Index", "Home")); } IEnumerable <BlogPost> model = manager.GetBlogsByCatagory(id).BlogsInCatagory; return(View(model)); }
public ActionResult AddPost(AddBlogViewModel model) { var hashMgr = HashTagManagerFactory.Create(); var cateMgr = CategoryRepoManagerFactory.Create(); var cResponse = cateMgr.GetCatagory(model.CatagoryId); model.Catagory = cResponse.CatagoryGot; model.BlogPost.CatagoryId = model.Catagory.CatagoryId; model.BlogPost.BlogPostHashTags = new List <HashTag>(); model.BlogPost.Approved = false; model.BlogPost.Id = User.Identity.GetUserId(); model.BlogPost.UserName = User.Identity.Name; foreach (var id in model.SelectedHashtagIds) { var response = hashMgr.GetHashTag(id); model.BlogPost.BlogPostHashTags.Add(response.HashTag); } if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { var savepath = Server.MapPath("~/Images"); string fileName = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName); string extension = Path.GetExtension(model.ImageUpload.FileName); var filePath = Path.Combine(savepath, fileName + extension); int counter = 1; while (System.IO.File.Exists(filePath)) { filePath = Path.Combine(savepath, fileName + counter.ToString() + extension); counter++; } model.ImageUpload.SaveAs(filePath); model.BlogPost.HeaderImage = Path.GetFileName(filePath); } if (ModelState.IsValid) { var blogMgr = BlogPostRepoManagerFactory.Create(); blogMgr.AddBlog(model.BlogPost); return(RedirectToAction("EditPost", "Blogger", new { blogId = model.BlogPost.BlogPostId })); } return(View(model)); }
public ActionResult Blogs() { var blogMgr = BlogPostRepoManagerFactory.Create(); var hashMgr = HashTagManagerFactory.Create(); var cateMgr = CategoryRepoManagerFactory.Create(); var approved = blogMgr.GetAllApprovedBlogPosted(); var notApproved = blogMgr.GetAllDisapprovedBlogs(); List <HashTag> tags = new List <HashTag>(); foreach (var blog in approved.Blogs) { cateMgr.AddCatagoryToBlogPost(blog.BlogPostId, blog.CatagoryId); var hashtags = hashMgr.GetHashTagsForBlog(blog.BlogPostId); tags = hashtags.HashTags.ToList(); blog.BlogPostHashTags = new List <HashTag>(); foreach (var ht in tags) { blog.BlogPostHashTags.Add(ht); } } foreach (var blag in notApproved.BlogPosts) { cateMgr.AddCatagoryToBlogPost(blag.BlogPostId, blag.CatagoryId); var hashtags = hashMgr.GetHashTagsForBlog(blag.BlogPostId); tags = hashtags.HashTags.ToList(); blag.BlogPostHashTags = new List <HashTag>(); foreach (var ht in tags) { blag.BlogPostHashTags.Add(ht); } } var groupModel = new GroupedBlogViewModel { ApprovedBlogs = approved.Blogs, UnApprovedBlogs = notApproved.BlogPosts }; return(View(groupModel)); }