Exemplo n.º 1
0
        public List <BlogPost> GetAllPosts()
        {
            var repo = BlogFactory.CreatBlogPostRepository();
            var post = repo.GetAllPosts();

            return(post);
        }
Exemplo n.º 2
0
        public void AddTagFromBridge(BlogPost id)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            foreach (var tag in id.Tags)
            {
                repo.InsertTagBlogBridgeTable(tag.Id, id.Id);
            }
        }
Exemplo n.º 3
0
        public List <BlogPost> GetUnapprovedBlogPosts()
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            var allPosts = repo.GetAllPosts();

            var results = from p in allPosts
                          where p.Approved == Approved.Waiting
                          select p;

            return(results.ToList());
        }
Exemplo n.º 4
0
        public List <BlogPost> GetCategoryPosts(StaticPage page)
        {
            var repo          = BlogFactory.CreatBlogPostRepository();
            var categoryPosts = new List <BlogPost>();
            var posts         = repo.GetAllPosts();

            foreach (var post in posts)
            {
                if (page.Category == post.Category)
                {
                    categoryPosts.Add(post);
                }
            }
            return(categoryPosts);
        }
Exemplo n.º 5
0
        public void EditBlogPost(BlogPost postToEdit)
        {
            var taglist  = new List <Tag>();
            var posttags = postToEdit.TagPlaceHolder;
            var manager  = new TagManager();
            var repo     = BlogFactory.CreatBlogPostRepository();

            // edit tags
            DeleteTagFromBridge(postToEdit);
            taglist         = manager.addTagToPost(posttags, postToEdit.Id);
            postToEdit.Tags = taglist;
            AddTagFromBridge(postToEdit);


            // edit images
            repo.EditBlogPost(postToEdit);
        }
Exemplo n.º 6
0
        public void RemoveBlogPost(BlogPost postToRemove)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            DeleteImageFromBridge(postToRemove);
            if (postToRemove.Imgs != null)
            {
                foreach (var img in postToRemove.Imgs)
                {
                    DeleteImage(img);
                }
            }

            DeleteTagFromBridge(postToRemove);

            repo.RemoveBlogPost(postToRemove);
        }
Exemplo n.º 7
0
        public BlogPost GetPostByID(int id)
        {
            PostResponse response = new PostResponse();

            var repo = BlogFactory.CreatBlogPostRepository();
            var post = repo.GetPostByID(id);


            if (post != null)
            {
                response.Success  = true;
                response.Message  = "It worked!";
                response.BlogPost = post;
            }
            else
            {
                response.Success = false;
                response.Message = "Post not found!";
            }
            return(post);
        }
Exemplo n.º 8
0
        public void AddBlogPost(BlogPost postToAdd)
        {
            var repo     = BlogFactory.CreatBlogPostRepository();
            var taglist  = new List <Tag>();
            var posttags = postToAdd.TagPlaceHolder;
            var manager  = new TagManager();

            taglist        = manager.addTagToPost(posttags, postToAdd.Id);
            postToAdd.Tags = taglist;
            repo.AddBlogPost(postToAdd);

            foreach (var img in postToAdd.Imgs)
            {
                if (img.Source != null)
                {
                    AddImage(img, postToAdd.Id);
                    //AddImageFromBridge(postToAdd.Id, img.Id);
                }
            }

            AddTagFromBridge(postToAdd);
        }
Exemplo n.º 9
0
        public List <BlogPost> GetTagPosts(StaticPage page)
        {
            var repo     = BlogFactory.CreatBlogPostRepository();
            var tagposts = new List <BlogPost>();
            var posts    = repo.GetAllPosts();

            foreach (var tag in page.Tag)
            {
                foreach (var post in posts)
                {
                    foreach (var posttag in post.Tags)
                    {
                        if (tag.Name == posttag.Name)
                        {
                            var postbytag = post;
                            tagposts.Add(postbytag);
                        }
                    }
                }
            }

            return(tagposts);
        }
Exemplo n.º 10
0
        public void DeleteTagFromBridge(BlogPost id)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            repo.DeleteTagBlogBridgeTable(id);
        }
Exemplo n.º 11
0
        public void DeleteImage(Img imgToDelete)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            repo.RemoveImageToBlogPost(imgToDelete);
        }
Exemplo n.º 12
0
        public void AddImageFromBridge(int imgId, int newBlogId)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            repo.InsertImgBlogBridgeTable(imgId, newBlogId);
        }
Exemplo n.º 13
0
        public void AddImage(Img imgToAdd, int blogId)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            repo.AddImageToBlogPost(imgToAdd, blogId);
        }
Exemplo n.º 14
0
        public void addPostCheckThenDelete()
        {
            var repo    = BlogFactory.CreatBlogPostRepository();
            var manager = new PostManager();

            BlogPost testPost = new BlogPost();
            var      filename = "test.png";
            var      imgs     = new List <Img>();
            var      tags     = new List <Tag>();

            testPost.Headline       = "Testing";
            testPost.Subtitle       = "Test Sub";
            testPost.Body           = "Testing again";
            testPost.AuthorName     = "Test";
            testPost.Approved       = Approved.Yes;
            testPost.Category       = Category.Anime;
            testPost.DateCreated    = DateTime.Today;
            testPost.TagPlaceHolder = "Test1,Test2";
            var img = new Img()
            {
                Description = "Test description",
                Title       = "Test title",
                Source      = filename
            };

            imgs.Add(img);
            testPost.Imgs = imgs;

            Tag tag1 = new Tag()
            {
                Name = "Test1"
            };

            tags.Add(tag1);
            Tag tag2 = new Tag()
            {
                Name = "Test2"
            };

            tags.Add(tag2);

            testPost.Tags = tags;

            repo.AddBlogPost(testPost);
            List <BlogPost> posts = repo.GetAllPosts();

            BlogPost check = posts.Last();

            Assert.AreEqual("Test Sub", check.Subtitle);
            Assert.AreEqual("Testing", check.Headline);
            Assert.AreEqual("Testing again", check.Body);
            Assert.AreEqual("Testing", check.Headline);
            //Assert.AreEqual("Test1", check.Tags[0].Name);
            //Assert.AreEqual("Test2", check.Tags[1].Name);
            //Assert.AreEqual("Test Title", check.Imgs[0].Title);
            //Assert.AreEqual("Test description", check.Imgs[0].Description);

            repo.RemoveBlogPost(testPost);

            Assert.IsNull(repo.GetPostByID(testPost.Id));
        }