当前位置: 首页>>代码示例>>C#>>正文


C# Page.AddTag方法代码示例

本文整理汇总了C#中Page.AddTag方法的典型用法代码示例。如果您正苦于以下问题:C# Page.AddTag方法的具体用法?C# Page.AddTag怎么用?C# Page.AddTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Page的用法示例。


在下文中一共展示了Page.AddTag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSuccessfulBlogTest

        public void CreateSuccessfulBlogTest()
        {
            using (UnitOfWork uow = new UnitOfWork())
            {
                BlogRepository br = new BlogRepository(uow.Current);
                //Creo il blog
                Devevil.Blog.Model.Domain.Entities.Blog b = new Devevil.Blog.Model.Domain.Entities.Blog(".Net Help", "Un blog dedicato allo sviluppo");
                //creo una categoria generica
                Category c = new Category("Nessuna categoria", "Categoria generica");
                //Creo un paio di TAG
                Tag t1 = new Tag("C#");
                Tag t2 = new Tag(".NET");
                //Creo un autore, afferente al blog "b"
                Author a = new Author("Pasquale", "Garzillo", Convert.ToDateTime("27/12/1987"), "[email protected]",true,"rofox2011",b);
                //Creo una pagina afferente al blog "b", che ha per autore "a" ed appartiene alla categoria "c"
                Page p = new Page("Prima pagina del blog", "Descrizione della prima pagina", DateTime.Today, "testo pagina", a, b, c);
                //Creo un commento per la pagina "p"
                Comment co = new Comment("Raowyr", "[email protected]", "Testo commento", p);
                
                //Aggiunto i tag "t1" e "t2" alla pagina
                p.AddTag(t1);
                p.AddTag(t2);
                //Aggiungo il commento "co" alla pagina
                p.AddComment(co);

                //Aggiungo la pagina "p" al blog "b"
                b.AddPageToBlog(p);
                //Aggiungo l'autore "a" al blog "b"
                b.AddAuthorToBlog(a);

                //La categoria "c" è categoria della pagina "p"
                c.AddCategoryToPage(p);
                //L'autore "a" è autore della pagina "p"
                a.AddAuthoringPage(p);
                //Tag "t1" e "t2" sono tag delle pagina "p"
                t1.AddTagToPage(p);
                t2.AddTagToPage(p);

                br.Save(b);

                uow.Commit();

                Devevil.Blog.Model.Domain.Entities.Blog bb = br.GetById(b.Id);

                Assert.IsNotNull(bb);
            }
        }
开发者ID:raowyr,项目名称:BlogProject,代码行数:47,代码来源:BlogRepositoryTest.cs

示例2: PageNew

        public ActionResult PageNew(PageViewModel model) 
        {
            try
            {
                //Carica tutti gli elementi necessari a video
                using (UnitOfWork uow = new UnitOfWork())
                {
                    AuthorRepository ar = new AuthorRepository(uow.Current);
                    BlogRepository br = new BlogRepository(uow.Current);
                    CategoryRepository cr = new CategoryRepository(uow.Current);

                    //Ricarica la lista autori
                    IList<Author> tmpAuthors = ar.FindAll().ToList();
                    if (tmpAuthors != null && tmpAuthors.Count > 0)
                    {
                        IEnumerable<SelectListItem> tmpAuthorsItems;

                        tmpAuthorsItems = from s in tmpAuthors
                                          select new SelectListItem
                                          {
                                              Text = s.NameAndSurname,
                                              Value = s.Id.ToString()
                                          };

                        model.Authors = tmpAuthorsItems;
                    }

                    IList<Blog.Model.Domain.Entities.Blog> tmpBlogs = br.FindAll().ToList();
                    if (tmpBlogs != null && tmpBlogs.Count > 0)
                    {
                        IEnumerable<SelectListItem> tmpBlogsItems;

                        tmpBlogsItems = from b in tmpBlogs
                                        select new SelectListItem
                                        {
                                            Text = b.Name,
                                            Value = b.Id.ToString()
                                        };

                        model.Blogs = tmpBlogsItems;
                    }

                    IList<Category> tmpCategories = cr.FindAll().ToList();
                    if (tmpCategories != null && tmpCategories.Count > 0)
                    {
                        IEnumerable<SelectListItem> tmpCategoriesItems;

                        tmpCategoriesItems = from b in tmpCategories
                                             select new SelectListItem
                                             {
                                                 Text = b.Name,
                                                 Value = b.Id.ToString()
                                             };

                        model.Categories = tmpCategoriesItems;
                    }
                }

                if (ModelState.IsValid)
                {
                    using (UnitOfWork uow = new UnitOfWork())
                    {
                        string fileName = null;
                        if (model.File != null && model.File.ContentLength > 0)
                        {
                            //SALVA IL FILE
                            fileName = Path.GetFileName(model.File.FileName);
                            var path = Path.Combine(Server.MapPath("/Uploads"), fileName);
                            model.File.SaveAs(path);
                            model.FileName = fileName;
                        }

                        model.SelectedAuthor = model.SelectedAuthor;
                        model.SelectedBlog = model.SelectedBlog;
                        model.SelectedCategory = model.SelectedCategory;

                        PageRepository pr = new PageRepository(uow.Current);
                        AuthorRepository ar = new AuthorRepository(uow.Current);
                        BlogRepository br = new BlogRepository(uow.Current);
                        CategoryRepository cr = new CategoryRepository(uow.Current);
                        TagRepository tr = new TagRepository(uow.Current);

                        Author au = ar.GetById(Convert.ToInt32(model.SelectedAuthor));
                        Blog.Model.Domain.Entities.Blog bb = br.GetById(Convert.ToInt32(model.SelectedBlog));
                        Category cc = cr.GetById(Convert.ToInt32(model.SelectedCategory));

                        Page p = new Page(model.Titolo, model.Descrizione, model.Data, model.Body, au, bb, cc);

                        if (!String.IsNullOrEmpty(model.Tags))
                        {
                            foreach(var t in model.Tags.Split(','))
                            {
                                if (!String.IsNullOrEmpty(t))
                                {
                                    Tag tg = tr.GetTagByName(t.TrimStart().TrimEnd());
                                    if (tg != null)
                                    {
                                        p.AddTag(tg);
                                    }
                                    else
//.........这里部分代码省略.........
开发者ID:raowyr,项目名称:BlogProject,代码行数:101,代码来源:ManageController.cs


注:本文中的Page.AddTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。