Example #1
0
        public void EFCanDeleteBlogPost()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            //add a blogpost first so I can try deleting it in the next step
            BlogPost newBlogPost = new BlogPost();

            newBlogPost.Title          = "Hey, This New Post!";
            newBlogPost.BlogContent    = "Code and Talk and Code and Talk and Code and Talk. Success!";
            newBlogPost.EventDate      = new DateTime(2017, 10, 30);
            newBlogPost.DateStart      = new DateTime(2017, 11, 01);
            newBlogPost.DateEnd        = new DateTime(2017, 01, 01);
            newBlogPost.BlogCategoryId = 2;
            newBlogPost.BlogStatusId   = 2;
            newBlogPost.IsFeatured     = false;
            newBlogPost.IsStaticPage   = false;

            //check to make sure it added ok
            repo.CreateNewBlogPost(newBlogPost);
            var addBlog = repo.GetAllPosts();

            Assert.AreEqual(6, addBlog.Count);

            //check to make sure that it deleted ok
            repo.DeleteBlogPostDraft(4);
            var deleteThis = repo.GetAllPosts();

            Assert.AreEqual(5, deleteThis.Count);
        }
Example #2
0
        public IHttpActionResult EditBlogPost(BlogPost newBlogPost)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BlogPost blogPost = TechTruffleRepositoryFactory.Create().GetBlogPostById(newBlogPost.BlogPostId);

            if (blogPost == null)
            {
                return(NotFound());
            }

            blogPost.Title          = newBlogPost.Title;
            blogPost.BlogContent    = newBlogPost.BlogContent;
            blogPost.EventDate      = newBlogPost.EventDate;
            blogPost.DateStart      = newBlogPost.DateStart;
            blogPost.DateEnd        = newBlogPost.DateEnd;
            blogPost.BlogCategoryId = newBlogPost.BlogCategoryId;
            blogPost.BlogStatusId   = newBlogPost.BlogStatusId;
            blogPost.IsFeatured     = newBlogPost.IsFeatured;
            blogPost.IsStaticPage   = newBlogPost.IsStaticPage;
            blogPost.Hashtags       = newBlogPost.Hashtags;

            blogPost.User         = newBlogPost.User;
            blogPost.BlogCategory = newBlogPost.BlogCategory;
            blogPost.BlogStatus   = newBlogPost.BlogStatus;

            TechTruffleRepositoryFactory.Create().EditBlogPost(newBlogPost);
            return(Ok(blogPost));
        }
Example #3
0
        public IHttpActionResult CreateNewBlogPost(BlogPost newblogPost)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BlogPost blogPost = new BlogPost()
            {
                Title          = newblogPost.Title,
                BlogContent    = newblogPost.BlogContent,
                EventDate      = newblogPost.EventDate,
                DateStart      = newblogPost.DateStart,
                DateEnd        = newblogPost.DateEnd,
                BlogCategoryId = newblogPost.BlogCategoryId,
                BlogStatusId   = newblogPost.BlogStatusId,
                IsFeatured     = newblogPost.IsFeatured,
                IsStaticPage   = newblogPost.IsStaticPage,
                Hashtags       = newblogPost.Hashtags,

                User         = newblogPost.User,
                BlogCategory = newblogPost.BlogCategory,
                BlogStatus   = newblogPost.BlogStatus
            };

            TechTruffleRepositoryFactory.Create().CreateNewBlogPost(newblogPost);
            return(Created($"blog/{newblogPost.BlogPostId}", newblogPost));
        }
Example #4
0
        public ActionResult CreateBlog()
        {
            var viewModel = new BlogPostViewModel();

            viewModel.SetCategoryItems(TechTruffleRepositoryFactory.Create().GetAllBlogCategories());
            return(View(viewModel));
        }
Example #5
0
        public void CanDeleteBlogPost()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            //add a blogpost first so I can try deleting it in the next step
            BlogPost newBlogPost = new BlogPost();

            newBlogPost.Title          = "Hey, This New Post!";
            newBlogPost.BlogContent    = "Code and Talk and Code and Talk and Code and Talk. Success!";
            newBlogPost.EventDate      = new DateTime(2017, 10, 30);
            newBlogPost.DateStart      = new DateTime(2017, 11, 01);
            newBlogPost.DateEnd        = new DateTime(2017, 01, 01);
            newBlogPost.BlogCategoryId = 2;
            newBlogPost.BlogStatusId   = 2;
            newBlogPost.IsFeatured     = false;
            newBlogPost.IsStaticPage   = false;
            newBlogPost.Hashtags       = null;

            //check to make sure it added ok
            repo.CreateNewBlogPost(newBlogPost);
            var loaded = repo.GetBlogPostById(5);

            Assert.IsNotNull(loaded);

            //check to make sure that it deleted ok
            repo.DeleteBlogPostDraft(5);
            loaded = repo.GetBlogPostById(5);
            Assert.IsNull(loaded);
        }
Example #6
0
 public ActionResult CreateStaticPage(StaticPage model)
 {
     if (ModelState.IsValid)
     {
         TechTruffleRepositoryFactory.Create().CreateStaticPage(model);
     }
     return(RedirectToAction("Index"));
 }
Example #7
0
        //[Authorize(Roles = "admin,author")]
        public ActionResult Blogs()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var model = repo.GetAllPublishedPosts();

            return(View(model));
        }
Example #8
0
        public void EFCanGetAllPendingPosts()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var pendingPosts = repo.GetAllPendingPosts();

            Assert.AreEqual(1, pendingPosts.Count);
        }
Example #9
0
        public ActionResult Index()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var model = repo.GetAllFeaturedPosts();

            return(View(model));
        }
Example #10
0
        public void EFCanGetBlogPostById()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var blogsById = repo.GetBlogPostById(2);

            Assert.AreEqual("Hack-o-Thon", blogsById.Title);
        }
Example #11
0
        public void EFCanGetAllStaticPages()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var staticPage = repo.GetAllStaticPages();

            Assert.AreEqual(0, staticPage.Count);
        }
Example #12
0
        public ActionResult StaticPages(int id)
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var model = repo.GetStaticPageByID(id);

            return(View(model));
        }
Example #13
0
        public void EFCanGetAllRemovedPosts()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var removedPosts = repo.GetAllRemovedPosts();

            Assert.AreEqual(1, removedPosts.Count);
            Assert.AreEqual(4, removedPosts[0].BlogPostId);
        }
Example #14
0
        public void EFCanGetAllPublishedPostsByHashtag()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var publishedPosts = repo.GetAllPublishedPostsByHashtag("#VirtualReality");

            Assert.AreEqual(1, publishedPosts.Count);
            Assert.AreEqual(2, publishedPosts[0].BlogPostId);
        }
Example #15
0
        public void EFCanGetAllPublishedPostsByCategory()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var publishedPostsbyCategory = repo.GetAllPublishedPostsByCategory(4);

            Assert.AreEqual(1, publishedPostsbyCategory.Count);
            Assert.AreEqual(2, publishedPostsbyCategory[0].BlogPostId);
        }
Example #16
0
        public void EFCanGetAllDraftsByOneAuthor()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var drafts = repo.GetAllDraftsByOneAuthor("Lindsey");

            Assert.AreEqual(1, drafts.Count);
            Assert.AreEqual(1, drafts[0].BlogPostId);
        }
Example #17
0
        public void EFCanGetPublishedPostsByTitle()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var publishedPosts = repo.GetPublishedPostsByTitle("Hack");

            Assert.AreEqual(1, publishedPosts.Count);
            Assert.AreEqual(2, publishedPosts[0].BlogPostId);
        }
Example #18
0
        public void CanGetAllRemovedPosts()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var removedPosts = repo.GetAllRemovedPosts();

            Assert.AreEqual(1, removedPosts.Count);
            Assert.AreEqual(5, removedPosts[0].BlogPostId);
            Assert.AreEqual("Testing to see if I'm removed", removedPosts[0].Title);
        }
Example #19
0
        public void EFCanGetAllDrafts()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var drafts = repo.GetAllDrafts();

            Assert.AreEqual(2, drafts.Count);
            Assert.AreEqual(3, drafts[1].BlogPostId);
            Assert.AreEqual("Grace Hopper Viewing party", drafts[1].Title);
        }
Example #20
0
        public void CanGetAllPublishedPostsByAuthor()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var publishedPostsByOneAuthor = repo.GetAllPublishedPostsByAuthor("Judy Thao");

            Assert.AreEqual(1, publishedPostsByOneAuthor.Count);
            Assert.AreEqual(2, publishedPostsByOneAuthor[0].BlogPostId);
            Assert.AreEqual("Guide to Getting the Job", publishedPostsByOneAuthor[0].Title);
        }
Example #21
0
        public void CanGetBlogPostById()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var blogsById = repo.GetBlogPostById(3);

            Assert.AreEqual("Tech Beers and Cheers", blogsById.Title);
            Assert.AreEqual("AJ", blogsById.User.FirstName);
            Assert.AreEqual("Rohde", blogsById.User.LastName);
        }
Example #22
0
        public void CanGetAllPublishedPostsByHashtag()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var publishedPosts = repo.GetAllPublishedPostsByHashtag("#InItToWinIt");

            Assert.AreEqual(1, publishedPosts.Count);
            Assert.AreEqual(2, publishedPosts[0].BlogPostId);
            Assert.AreEqual("Guide to Getting the Job", publishedPosts[0].Title);
        }
Example #23
0
        public void CanGetAllDrafts()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var drafts = repo.GetAllDrafts();

            Assert.AreEqual(2, drafts.Count);
            Assert.AreEqual(4, drafts[1].BlogPostId);
            Assert.AreEqual("Let's Get Together and Code", drafts[1].Title);
        }
Example #24
0
        public void CanGetAllFeaturedPosts()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var featuredPosts = repo.GetAllFeaturedPosts();

            Assert.AreEqual(1, featuredPosts.Count);
            Assert.AreEqual(2, featuredPosts[0].BlogPostId);
            Assert.AreEqual("Guide to Getting the Job", featuredPosts[0].Title);
        }
Example #25
0
        public void CanGetAllPendingPosts()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var pendingPosts = repo.GetAllPendingPosts();

            Assert.AreEqual(1, pendingPosts.Count);
            Assert.AreEqual(3, pendingPosts[0].BlogPostId);
            Assert.AreEqual("Tech Beers and Cheers", pendingPosts[0].Title);
        }
Example #26
0
        public void EFCanGetAllPosts()
        {
            var repo = TechTruffleRepositoryFactory.Create();

            var blogPosts = repo.GetAllPosts();

            Assert.AreEqual(5, blogPosts.Count);
            Assert.AreEqual(4, blogPosts[1].BlogCategoryId);
            Assert.AreEqual(3, blogPosts[1].BlogStatusId);
            Assert.IsTrue(blogPosts[1].IsFeatured);
        }
Example #27
0
        public IHttpActionResult GetAllNonDraftBlogs()
        {
            List <BlogPost> blogPosts = TechTruffleRepositoryFactory.Create().GetAllNonDraftBlogs();

            if (blogPosts == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(blogPosts));
            }
        }
Example #28
0
        public IHttpActionResult GetAllBlogsRemovedBlogsByAuthor(string author)
        {
            List <BlogPost> blogPosts = TechTruffleRepositoryFactory.Create().GetAllBlogsRemovedBlogsByAuthor(author);

            if (blogPosts == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(blogPosts));
            }
        }
Example #29
0
        public IHttpActionResult GetAllStaticPages()
        {
            List <StaticPage> staticPages = TechTruffleRepositoryFactory.Create().GetAllStaticPages();

            if (staticPages == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(staticPages));
            }
        }
Example #30
0
        public IHttpActionResult GetAllDraftsByOneAuthor(string userName)
        {
            List <BlogPost> blogPosts = TechTruffleRepositoryFactory.Create().GetAllDraftsByOneAuthor(userName);

            if (blogPosts == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(blogPosts));
            }
        }