Example #1
0
 public ActionResult CreateBlog(BlogEntity Blog)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ValidationFactory    VF         = new ValidationFactory();
             BlogFactory          AddBlog    = new BlogFactory();
             DataLayer.tblBlog    NewBlog    = new DataLayer.tblBlog();
             DataLayer.tblChannel NewChannel = new DataLayer.tblChannel();
             string Message = VF.BlogValidity(Blog.BlogName, null);
             if (Message != "Success")
             {
                 ModelState.AddModelError("BlogName", Message);
                 GetTopic();
                 return(View(Blog));
             }
             else
             {
                 NewBlog.BlogName    = Blog.BlogName;
                 NewBlog.BlogHeading = Blog.BlogHeading;
                 NewBlog.TopicId     = Blog.TopicId;
                 NewBlog.CreatedDate = DateTime.Now;
                 NewBlog.CreatedBy   = null;
                 NewBlog.UpdatedDate = null;
                 NewBlog.UpdatedBy   = null;
                 NewBlog.IsActive    = true;
                 AddBlog.SaveBlog(NewBlog);
                 return(RedirectToAction("Blog"));
             }
         }
         else
         {
             GetTopic();
             return(View(Blog));
         }
     }
     catch (Exception Ex)
     {
         GetTopic();
         return(View());
     }
     finally { GetTopic(); }
 }
Example #2
0
        private async Task AddBlogAsync(string blogUrl)
        {
            if (string.IsNullOrEmpty(blogUrl))
            {
                blogUrl = crawlerService.NewBlogUrl;
            }

            IBlog blog;

            try
            {
                blog = BlogFactory.GetBlog(blogUrl, Path.Combine(shellService.Settings.DownloadLocation, "Index"));
            }
            catch (ArgumentException)
            {
                return;
            }

            if ((blog.GetType() == typeof(TumblrBlog)) && await TumblrBlogDetector.IsHiddenTumblrBlog(blog.Url))
            {
                blog = PromoteTumblrBlogToHiddenBlog(blog);
            }

            lock (lockObject)
            {
                if (managerService.BlogFiles.Any(blogs => blogs.Name.Equals(blog.Name) && blogs.BlogType.Equals(blog.BlogType)))
                {
                    shellService.ShowError(null, Resources.BlogAlreadyExist, blog.Name);
                    return;
                }

                if (blog.Save())
                {
                    AddToManager(blog);
                }
            }

            blog = settingsService.TransferGlobalSettingsToBlog(blog);
            ICrawler crawler = CrawlerFactory.GetCrawler(blog, new CancellationToken(), new PauseToken(), new Progress <DownloadProgress>(), shellService, crawlerService, managerService);
            await crawler.UpdateMetaInformationAsync();
        }
Example #3
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);
        }
Example #4
0
        public override async Task <BlogDTO> AddAsync(BlogDTO blogDTO)
        {
            if (blogDTO == null)
            {
                throw new ArgumentException(_resources.GetStringResource(LocalizationKeys.Application.validation_No_Records_Found_Error));
            }

            Blog blog = BlogFactory.CreateBlog(blogDTO.Name, blogDTO.Url, blogDTO.Rating);

            if (_validator.IsValid <Blog>(blog))
            {
                _blogRepository.Add(blog);

                await _blogRepository.UnitOfWork.CommitAsync();

                return(blog.ProjectedAs <BlogDTO>());
            }
            else
            {
                throw new ApplicationValidationErrorsException(_validator.GetInvalidMessages <Blog>(blog));
            }
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
0
 private bool CanAddBlog()
 {
     return(BlogFactory.IsValidTumblrBlogUrl(crawlerService.NewBlogUrl));
 }
Example #8
0
        public void DeleteTagFromBridge(BlogPost id)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            repo.DeleteTagBlogBridgeTable(id);
        }
Example #9
0
        public void DeleteImage(Img imgToDelete)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            repo.RemoveImageToBlogPost(imgToDelete);
        }
Example #10
0
        public void AddImageFromBridge(int imgId, int newBlogId)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            repo.InsertImgBlogBridgeTable(imgId, newBlogId);
        }
Example #11
0
        public void AddImage(Img imgToAdd, int blogId)
        {
            var repo = BlogFactory.CreatBlogPostRepository();

            repo.AddImageToBlogPost(imgToAdd, blogId);
        }
Example #12
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));
        }