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 void CanGetHashTags() { var manager = HashTagManagerFactory.Create(); var response = manager.GetAllHashTags(); Assert.IsNotNull(response.HashTags); Assert.IsTrue(response.Success); }
public ActionResult ApproveHashtag(int hashTagId) { var hashMgr = HashTagManagerFactory.Create(); var hashtag = hashMgr.GetHashTag(hashTagId); hashMgr.ApproveHashTag(hashtag.HashTag.HashTagId); return(RedirectToAction("HashTags")); }
public void CanGetUnapprovedHashTags() { var manager = HashTagManagerFactory.Create(); var response = manager.GetUnapprovedHashtags(); Assert.IsNotNull(response.HashTags); Assert.IsTrue(response.Success); Assert.AreEqual(3, response.HashTags[0].HashTagId); Assert.AreEqual("#moon", response.HashTags[0].HashTagName); Assert.IsFalse(response.HashTags[0].Approved); }
public ActionResult EditHashTag(int hashTagId) { var hashMgr = HashTagManagerFactory.Create(); var toEdit = hashMgr.GetHashTag(hashTagId); var model = new EditHashTagViewModel(); model.HashTag = toEdit.HashTag; return(View(model)); }
public ActionResult HashTags() { var hashMgr = HashTagManagerFactory.Create(); var hashTags = hashMgr.GetAllHashTags(); var model = new HashTagListViewModel(); model.HashTags = hashTags.HashTags; return(View(model)); }
public void CanAddHashTag() { HashTag hashtag = new HashTag(5, "#fart", false); var manager = HashTagManagerFactory.Create(); var response = manager.AddHashTag(hashtag); Assert.IsNotNull(response.Hashtag); Assert.IsTrue(response.Success); Assert.AreEqual(5, response.Hashtag.HashTagId); Assert.AreEqual("#fart", response.Hashtag.HashTagName); Assert.IsFalse(response.Hashtag.Approved); }
public void CanGetHashtagById() { var manager = HashTagManagerFactory.Create(); var response = new GetHashTagResponse(); response = manager.GetHashTag(1); Assert.IsNotNull(response.HashTag); Assert.IsTrue(response.Success); Assert.AreEqual(1, response.HashTag.HashTagId); Assert.AreEqual("#metapost", response.HashTag.HashTagName); }
public ActionResult EditHashTag(EditHashTagViewModel model) { var hashMgr = HashTagManagerFactory.Create(); if (ModelState.IsValid) { hashMgr.EditHashTag(model.HashTag); return(RedirectToAction("HashTags")); } 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 void CanEditHashTag() { var manager = HashTagManagerFactory.Create(); var response = manager.GetHashTag(1); response.HashTag.HashTagName = "#poop"; response.HashTag.Approved = true; var edited = manager.EditHashTag(response.HashTag); Assert.IsNotNull(edited.HashTag); Assert.IsTrue(edited.Success); Assert.AreEqual(1, edited.HashTag.HashTagId); Assert.AreEqual("#poop", edited.HashTag.HashTagName); Assert.AreEqual(true, edited.HashTag.Approved); }
public ActionResult AddPost() { var model = new AddBlogViewModel(); var hashMgr = HashTagManagerFactory.Create(); var hashTags = hashMgr.GetAllHashTags(); var cataMgr = CategoryRepoManagerFactory.Create(); var categories = cataMgr.GetAllCategories(); model.HashTags = new SelectList(hashTags.HashTags, "HashTagId", "HashTagName"); model.Catagories = new SelectList(categories.Catagories, "CatagoryId", "CatagoryName"); 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)); }