コード例 #1
0
        public void CanGetRecentImages()
        {
            //arrange
            UnitTestHelper.SetupBlog();
            ObjectProvider provider = ObjectProvider.Instance();
            var            category = new LinkCategory
            {
                BlogId      = Config.CurrentBlog.Id,
                Description = "Whatever",
                IsActive    = true,
                Title       = "Whatever"
            };
            int categoryId = provider.CreateLinkCategory(category);

            var image = new Image
            {
                Title      = "Title",
                CategoryID = categoryId,
                BlogId     = Config.CurrentBlog.Id,
                FileName   = "Foo",
                Height     = 10,
                Width      = 10,
                IsActive   = true,
            };
            int imageId = provider.InsertImage(image);

            //act
            ICollection <Image> images = provider.GetImages(Config.CurrentBlog.Host, null, 10);

            //assert
            Assert.AreEqual(1, images.Count);
            Assert.AreEqual(imageId, images.First().ImageID);
        }
コード例 #2
0
        private void BindGallery(int galleryId)
        {
            CategoryId = galleryId;
            LinkCategory        selectedGallery = SubtextContext.Repository.GetLinkCategory(galleryId, false);
            ICollection <Image> imageList       = Images.GetImagesByCategoryId(galleryId, false);

            plhImageHeader.Controls.Clear();
            if (selectedGallery != null)
            {
                string galleryTitle = string.Format(CultureInfo.InvariantCulture, "{0} - {1} " + Resources.Label_Images,
                                                    selectedGallery.Title, imageList.Count);
                plhImageHeader.Controls.Add(new LiteralControl(galleryTitle));
            }
            else //invalid gallery
            {
                Messages.ShowError("The gallery does not exist anymore. Please update your bookmarks.");
                return;
            }

            rprImages.DataSource = imageList;
            rprImages.DataBind();

            ShowImages();

            if (AdminMasterPage != null)
            {
                string title = string.Format(CultureInfo.InvariantCulture, Resources.EditGalleries_ViewingGallery,
                                             selectedGallery.Title);
                AdminMasterPage.Title = title;
            }

            AddImages.Collapsed = !Preferences.AlwaysExpandAdvanced;
        }
コード例 #3
0
ファイル: LinkLogic.cs プロジェクト: yuabd/Service
        public BaseObject InsertLinkCategory(LinkCategoryEntity link)
        {
            BaseObject obj = new BaseObject();

            try
            {
                var category = new LinkCategory()
                {
                    Name        = link.Name,
                    SortOrder   = link.SortOrder,
                    DateCreated = DateTime.Now,
                    UpdateUser  = link.UpdateUser
                };

                _db.LinkCategories.Add(category);
                _db.SaveChanges();

                obj.Tag = 1;
            }
            catch (Exception)
            {
                obj.Tag = -1;
            }

            return(obj);
        }
コード例 #4
0
        private void GetPosts(XmlNode connectorNode, string currentFolder)
        {
            IPagedCollection <EntryStatsView> posts;

            if (currentFolder.Equals("/"))
            {
                posts = Repository.GetEntries(PostType.BlogPost, -1, 0, 1000);
            }
            else
            {
                string       categoryName = currentFolder.Substring(1, currentFolder.Length - 2);
                LinkCategory cat          = ObjectProvider.Instance().GetLinkCategory(categoryName, false);
                posts = Repository.GetEntries(PostType.BlogPost, cat.Id, 0, 1000);
            }

            // Create the "Files" node.
            XmlNode oFilesNode = XmlUtil.AppendElement(connectorNode, "Files");

            foreach (var entry in posts)
            {
                // Create the "File" node.
                if (entry.IsActive)
                {
                    XmlNode oFileNode = XmlUtil.AppendElement(oFilesNode, "File");

                    //TODO: Seriously refactor.
                    var urlHelper = new UrlHelper(null, null);

                    XmlUtil.SetAttribute(oFileNode, "name",
                                         string.Format(CultureInfo.InvariantCulture, "{0}|{1}", entry.Title,
                                                       urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(Config.CurrentBlog)));
                    XmlUtil.SetAttribute(oFileNode, "size", entry.DateModified.ToShortDateString());
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Creates a new <see cref="CategoryWriter"/> instance.
 /// </summary>
 public CategoryWriter(TextWriter writer, ICollection <Entry> ec, LinkCategory lc, Uri url,
                       ISubtextContext context)
     : base(writer, ec, NullValue.NullDateTime, false, context)
 {
     Category = lc;
     Url      = url;
 }
コード例 #6
0
        protected ICollection <LinkCategory> GetArchiveCategories(Blog blog)
        {
            var linkCategories = new List <LinkCategory>();

            // we want to make sure that the LinkCategory is NOT null before we add it to the collection.
            LinkCategory category = Repository.Links(CategoryType.PostCollection, blog, Url);

            if (category != null)
            {
                linkCategories.Add(category);
            }
            category = Repository.Links(CategoryType.StoryCollection, blog, Url);
            if (category != null)
            {
                linkCategories.Add(category);
            }
            category = Repository.ArchiveMonth(Url, blog);
            if (category != null)
            {
                linkCategories.Add(category);
            }
            category = Repository.Links(CategoryType.ImageCollection, blog, Url);
            if (category != null)
            {
                linkCategories.Add(category);
            }
            return(linkCategories);
        }
コード例 #7
0
ファイル: MetaBlogApiTests.cs プロジェクト: ghjigan/Subtext
        public void getCategories_ReturnsCategoriesInRepository()
        {
            //arrange
            var blog = new Blog {
                AllowServiceAccess = true, Host = "localhost", UserName = "******", Password = "******"
            };
            var category = new LinkCategory
            {
                BlogId       = blog.Id,
                IsActive     = true,
                Description  = "Test category",
                Title        = "CategoryA",
                CategoryType = CategoryType.PostCollection,
                Id           = 42
            };

            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.UrlHelper.CategoryUrl(It.IsAny <LinkCategory>())).Returns("/Category/42.aspx");
            subtextContext.Setup(c => c.UrlHelper.CategoryRssUrl(It.IsAny <LinkCategory>())).Returns("/rss.aspx?catId=42");
            subtextContext.Setup(c => c.Repository.GetCategories(CategoryType.PostCollection, false)).Returns(new[] { category });
            subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock <IDependencyResolver>().Object);
            var api = new MetaWeblog(subtextContext.Object);

            //act
            CategoryInfo[] categories = api.getCategories(blog.Id.ToString(), "username", "password");

            //assert
            Assert.AreEqual(1, categories.Length);
            Assert.AreEqual("http://localhost/Category/42.aspx", categories[0].htmlUrl);
            Assert.AreEqual("http://localhost/rss.aspx?catId=42", categories[0].rssUrl);
        }
コード例 #8
0
        private void dgrCategories_DeleteCommand(object source, DataGridCommandEventArgs e)
        {
            int          id = Convert.ToInt32(dgrItems.DataKeys[e.Item.ItemIndex]);
            LinkCategory lc = SubtextContext.Repository.GetLinkCategory(id, false);

            ConfirmDelete(id, lc.Title);
        }
コード例 #9
0
        /// <summary>
        /// Will convert ArchiveCountCollection method from Archives.GetPostsByCategoryArchive()
        /// into a <see cref="LinkCategory"/>. LinkCategory is a common item to databind to a web control.
        /// </summary>
        public static LinkCategory BuildCategoriesArchiveLinks(string title, UrlHelper urlHelper)
        {
            ICollection <ArchiveCount> acc = Archives.GetPostCountByCategory();

            var category = new LinkCategory {
                Title = title
            };

            foreach (ArchiveCount ac in acc)
            {
                var link = new Link
                {
                    IsActive  = true,
                    NewWindow = false,
                    Title     = string.Format("{0} ({1})", ac.Title, ac.Count.ToString(CultureInfo.InvariantCulture)),
                    Url       = urlHelper.CategoryUrl(new Category {
                        Id = ac.Id, Title = ac.Title
                    })
                };
                //Ugh, I hate how categories work in Subtext. So intertwined with links.

                category.Links.Add(link);
            }
            return(category);
        }
コード例 #10
0
        public void CanGetCategoryByNameRequest()
        {
            //arrange
            var routeData = new RouteData();

            routeData.Values.Add("slug", "this-is-a-test");
            var requestContext = new RequestContext(new Mock <HttpContextBase>().Object, routeData);
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.RequestContext).Returns(requestContext);
            subtextContext.Setup(c => c.Blog).Returns(new Blog {
                Id = 123
            });
            subtextContext.Setup(c => c.Repository.GetLinkCategory("this-is-a-test", true))
            .Returns(new LinkCategory {
                Id = 99, Title = "this is a test"
            });
            subtextContext.Setup(c => c.Cache[It.IsAny <string>()]).Returns(null);

            //act
            LinkCategory category = Cacher.SingleCategory(subtextContext.Object);

            //assert
            Assert.AreEqual(99, category.Id);
        }
コード例 #11
0
ファイル: LinksTests.cs プロジェクト: sshamit/Subtext
        public void CanCreateAndDeleteLinkCategory()
        {
            UnitTestHelper.SetupBlog();
            var repository = new DatabaseObjectProvider();

            // Create some categories
            int categoryId =
                repository.CreateLinkCategory(CreateCategory("My Favorite Feeds", "Some of my favorite RSS feeds",
                                                             CategoryType.LinkCollection, true));

            LinkCategory category = repository.GetLinkCategory(categoryId, true);

            Assert.AreEqual(Config.CurrentBlog.Id, category.BlogId);
            Assert.AreEqual("My Favorite Feeds", category.Title);
            Assert.AreEqual("Some of my favorite RSS feeds", category.Description);
            Assert.IsTrue(category.HasDescription);
            Assert.IsFalse(category.HasLinks);
            Assert.IsFalse(category.HasImages);
            Assert.IsTrue(category.IsActive);
            Assert.AreEqual(CategoryType.LinkCollection, category.CategoryType);
            Assert.IsNotNull(category);

            repository.DeleteLinkCategory(categoryId);
            Assert.IsNull(repository.GetLinkCategory(categoryId, true));
        }
コード例 #12
0
        private void dgrSelectionList_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            var title = e.Item.FindControl("txbTitle") as TextBox;
            var desc  = e.Item.FindControl("txbDescription") as TextBox;

            var isActive = e.Item.FindControl("ckbIsActive") as CheckBox;

            if (Page.IsValid && null != title && null != isActive)
            {
                int id = Convert.ToInt32(dgrSelectionList.DataKeys[e.Item.ItemIndex]);

                LinkCategory existingCategory = SubtextContext.Repository.GetLinkCategory(id, false);
                existingCategory.Title    = title.Text;
                existingCategory.IsActive = isActive.Checked;
                if (desc != null)
                {
                    existingCategory.Description = desc.Text;
                }

                if (id != 0)
                {
                    PersistCategory(existingCategory);
                }

                dgrSelectionList.EditItemIndex = -1;
                BindList();
            }
        }
コード例 #13
0
        private void BindList()
        {
            if (categoryId != null)
            {
                LinkCategory category = Repository.GetLinkCategory(categoryId, false);
                if (category != null)
                {
                    HeaderText = Resources.Label_Posts.ToUpper(CultureInfo.CurrentCulture) + " (" + category.Title + ")";
                }
            }

            IPagedCollection <EntryStatsView> selectionList = Repository.GetEntries(EntryType, categoryId, pageIndex: pageIndex,
                                                                                    pageSize: resultsPager.PageSize);

            if (selectionList.Count > 0)
            {
                resultsPager.ItemCount      = selectionList.MaxItems;
                rprSelectionList.DataSource = selectionList;
                rprSelectionList.DataBind();
                NoMessagesLabel.Visible = false;
            }

            NoMessagesLabel.Visible = selectionList.Count <= 0;
            resultsPager.Visible    = rprSelectionList.Visible = selectionList.Count > 0;
        }
コード例 #14
0
        public PagedEntryByCategoryCollectionTester()
        {
            var category = new LinkCategory {
                BlogId = Config.CurrentBlog.Id, IsActive = true, Title = "Foobar", Description = "Unit Test"
            };

            _categoryId = Links.CreateLinkCategory(category);
        }
コード例 #15
0
 public override int CreateLinkCategory(LinkCategory lc)
 {
     return(_procedures.InsertCategory(lc.Title,
                                       lc.IsActive,
                                       BlogId,
                                       (int)lc.CategoryType,
                                       lc.Description ?? string.Empty));
 }
コード例 #16
0
 public void CreateCategories(BlogMLBlog blog)
 {
     foreach (BlogMLCategory bmlCategory in blog.Categories)
     {
         LinkCategory category = Mapper.ConvertCategory(bmlCategory);
         Repository.CreateLinkCategory(category);
     }
 }
コード例 #17
0
        public PagedEntryByCategoryCollectionTester()
        {
            var repository = new DatabaseObjectProvider();
            var category   = new LinkCategory {
                BlogId = Config.CurrentBlog.Id, IsActive = true, Title = "Foobar", Description = "Unit Test"
            };

            _categoryId = repository.CreateLinkCategory(category);
        }
コード例 #18
0
 public override bool UpdateLinkCategory(LinkCategory category)
 {
     return(_procedures.UpdateCategory(category.Id,
                                       category.Title,
                                       category.IsActive,
                                       (int)category.CategoryType,
                                       category.Description ?? string.Empty,
                                       BlogId));
 }
コード例 #19
0
        public ActionResult Details(int id = 0)
        {
            LinkCategory category = db.LinkCategories.Find(id);

            if (category == null)
            {
                return(HttpNotFound());
            }
            return(View(category));
        }
コード例 #20
0
        static LinkCategory CreateCategory(string title, string description, CategoryType categoryType, bool isActive)
        {
            var linkCategory = new LinkCategory();

            linkCategory.BlogId       = Config.CurrentBlog.Id;
            linkCategory.Title        = title;
            linkCategory.Description  = description;
            linkCategory.CategoryType = categoryType;
            linkCategory.IsActive     = isActive;
            return(linkCategory);
        }
コード例 #21
0
        /// <summary>
        /// Creates a blog post link category.
        /// </summary>
        /// <param name="blogId"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static int CreateCategory(int blogId, string title)
        {
            var category = new LinkCategory
            {
                BlogId       = Config.CurrentBlog.Id,
                Title        = title,
                CategoryType = CategoryType.PostCollection,
                IsActive     = true
            };

            return(Links.CreateLinkCategory(category));
        }
コード例 #22
0
        public ActionResult DeleteConfirmed(int id)
        {
            LinkCategory category = db.LinkCategories.Find(id);

            db.LinkCategories.Remove(category);
            db.SaveChanges();
            if (Request.IsAjaxRequest())
            {
                return(Content(null));
            }
            return(RedirectToAction("Index"));
        }
コード例 #23
0
ファイル: UnitTestHelper.cs プロジェクト: timheuer/Subtext
        /// <summary>
        /// Creates a blog post link category.
        /// </summary>
        /// <param name="blogId">The blog id.</param>
        /// <param name="title">The title.</param>
        /// <param name="categoryType">Type of the category.</param>
        /// <returns></returns>
        public static int CreateCategory(int blogId, string title, CategoryType categoryType)
        {
            var category = new LinkCategory
            {
                BlogId       = Config.CurrentBlog.Id,
                Title        = title,
                CategoryType = categoryType,
                IsActive     = true
            };

            return(new DatabaseObjectProvider().CreateLinkCategory(category));
        }
コード例 #24
0
ファイル: LinkService.cs プロジェクト: csu-xiao-an/LifeLike
 public IEnumerable <Link> List(LinkCategory category)
 {
     try
     {
         return(_repo.GetOverviewQuery(q => q.Category == category).ProjectTo <Link>().AsEnumerable());
     }
     catch (Exception e)
     {
         _logger.AddException(e);
         throw;
     }
 }
コード例 #25
0
ファイル: LinkRepository.cs プロジェクト: fossabot/LifeLike
        public async Task <IEnumerable <Link> > List(LinkCategory category)
        {
            try
            {
                return(await _context.Links.Where(p => p.Category == category).ToListAsync());
            }
            catch (Exception e)
            {
                await _logger.AddException(e);

                throw;
            }
        }
コード例 #26
0
        // w.bloggar workarounds/nominal MT support - HACKS

        // w.bloggar is not correctly implementing metaWeblogAPI on its getRecentPost call, it wants
        // an instance of blogger.getRecentPosts at various time.
        //
        // What works better with w.bloggar is to tell it to use MT settings. For w.bloggar users
        // with metaWeblog configured, we'll throw a more explanatory exception than method not found.

        // Wordpress API

        #region IWordPressApi Members

        public int newCategory(string blogid, string username, string password, WordpressCategory category)
        {
            var newCategory = new LinkCategory
            {
                CategoryType = CategoryType.PostCollection,
                Title        = category.name,
                IsActive     = true,
                Description  = category.name
            };

            newCategory.Id = Links.CreateLinkCategory(newCategory);

            return(newCategory.Id);
        }
コード例 #27
0
        public ActionResult Edit(int id = 0)
        {
            LinkCategory category = db.LinkCategories.Find(id);

            if (category == null)
            {
                return(HttpNotFound());
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView(category));
            }
            return(View(category));
        }
コード例 #28
0
 public ActionResult Edit(LinkCategory linkCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(linkCategory).State = EntityState.Modified;
         var responseSave = DBHelper.SaveChanges(db);
         if (responseSave.Succeeded)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, responseSave.Message);
     }
     return(View(linkCategory));
 }
コード例 #29
0
        protected override ICollection <Entry> GetFeedEntries()
        {
            if (Category == null)
            {
                Category = Cacher.SingleCategory(SubtextContext);
            }

            if (Category != null && _posts == null)
            {
                _posts = Cacher.GetEntriesByCategory(10, Category.Id, SubtextContext);
            }

            return(_posts);
        }
コード例 #30
0
 /// <summary>
 /// 控件处理
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         DataRowView  dv       = e.Item.DataItem as DataRowView;
         Int32        ID       = Convert.ToInt32(dv["id"]);
         LinkCategory linktype = (LinkCategory)Enum.Parse(typeof(LinkCategory), dv["groupid"].ToString(), true);
         if (linktype == LinkCategory.文字)
         {
             e.Item.FindControl("PlaceHolder1").Visible = false;
         }
         ImageButton del = e.Item.FindControl("del") as ImageButton;
         del.OnClientClick = String.Format("javascript:dialogConfirm({{el:this,text:'将删除 {0} 且无法恢复!确定要删除吗?'}});return false;", dv["linkname"]);
     }
 }