コード例 #1
0
ファイル: UIHelper.cs プロジェクト: stantoxt/Piranha.vNext
 /// <summary>
 /// Renders the permalink for the given post.
 /// </summary>
 /// <param name="post">The post</param>
 /// <returns>The generated permalink</returns>
 public string Permalink(Piranha.Models.Post post)
 {
     if (post.Type != null)
     {
         return(App.Env.Url("~/" + post.Type.Slug + "/" + post.Slug));
     }
     return(Permalink(Models.PostModel.GetById(post.Id)));
 }
コード例 #2
0
        /// <summary>
        /// Saves the current post edit model.
        /// </summary>
        /// <param name="api">The current api</param>
        public void Save(Api api)
        {
            var newModel = false;

            // Get or create post
            var post = Id.HasValue ? api.Posts.GetSingle(Id.Value) : null;

            if (post == null)
            {
                post     = new Piranha.Models.Post();
                newModel = true;
            }

            // Map values
            Mapper.Map <EditModel, Piranha.Models.Post>(this, post);

            // Check action
            if (Action == SubmitAction.Publish)
            {
                post.Published = DateTime.Now;
            }
            else if (Action == SubmitAction.Unpublish)
            {
                post.Published = null;
            }

            // Remove old categories
            post.Categories.Clear();

            // Map current categories
            if (!String.IsNullOrWhiteSpace(SelectedCategories))
            {
                foreach (var str in SelectedCategories.Split(new char[] { ',' }))
                {
                    var categoryName = str.Trim();

                    var cat = api.Categories.GetSingle(where : c => c.Title == categoryName);
                    if (cat == null)
                    {
                        cat = new Piranha.Models.Category()
                        {
                            Title = categoryName
                        };
                        api.Categories.Add(cat);
                    }
                    post.Categories.Add(cat);
                }
            }
            if (newModel)
            {
                api.Posts.Add(post);
            }
            api.SaveChanges();

            this.Id = post.Id;
        }
コード例 #3
0
ファイル: EditModel.cs プロジェクト: cdie/Piranha.vNext
		/// <summary>
		/// Saves the current post edit model.
		/// </summary>
		/// <param name="api">The current api</param>
		public void Save(Api api) {
			var newModel = false;

			// Get or create post
			var post = Id.HasValue ? api.Posts.GetSingle(Id.Value) : null;
			if (post == null) {
				post = new Piranha.Models.Post();
				newModel = true;
			}

			// Map values
			Mapper.Map<EditModel, Piranha.Models.Post>(this, post);

			// Check action
			if (Action == SubmitAction.Publish)
				post.Published = DateTime.Now;
			else if (Action == SubmitAction.Unpublish)
				post.Published = null;

			// Remove old categories
			post.Categories.Clear();

			// Map current categories
			if (!String.IsNullOrWhiteSpace(SelectedCategories)) {
				foreach (var str in SelectedCategories.Split(new char[] {','})) {
					var categoryName = str.Trim();

					var cat = api.Categories.GetSingle(where: c => c.Title == categoryName);
					if (cat == null) {
						cat = new Piranha.Models.Category() {
							Title = categoryName
						};
						api.Categories.Add(cat);
					}
					post.Categories.Add(cat);
				}
			}
			if (newModel)
				api.Posts.Add(post);
			api.SaveChanges();

			this.Id = post.Id;
		}
コード例 #4
0
ファイル: Global.asax.cs プロジェクト: stantoxt/Piranha.vNext
        /// <summary>
        /// Starts the MVC application.
        /// </summary>
        protected void Application_Start()
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            AreaRegistration.RegisterAllAreas();

            // Initialize the application instance with the ASP.NET runtime
            Piranha.App.Init(c => {
                c.Cache    = new Piranha.AspNet.Cache.HttpCache();
                c.Env      = new Piranha.AspNet.Env();
                c.Mail     = new Piranha.AspNet.Mail.SmtpMail();
                c.Security = new Piranha.AspNet.Security.SimpleSecurity("admin", "password");
                c.Store    = new Piranha.EntityFramework.Store();
            });

            #region Seed test data
            //
            // Let's get some default data going
            //
            using (var api = new Piranha.Api()) {
                // Only seed if we don't have any authors
                var seed = !api.Authors.Get().Any();

                if (!seed)
                {
                    return;
                }
                var author = api.Authors.GetSingle(@where: a => a.Name == "Håkan Edling");
                if (author == null)
                {
                    author = new Piranha.Models.Author()
                    {
                        Name  = "Håkan Edling",
                        Email = "*****@*****.**"
                    };
                    api.Authors.Add(author);
                    api.SaveChanges();
                }

                // Post type
                var type = api.PostTypes.GetSingle(@where: t => t.Slug == "blog");
                if (type == null)
                {
                    type = new Piranha.Models.PostType()
                    {
                        Name            = "Blog post",
                        EnableArchive   = true,
                        ArchiveTitle    = "Blog",
                        Slug            = "blog",
                        MetaKeywords    = "Piranha CMS, .NET, MVC, CMS, Blog",
                        MetaDescription = "Read the latest toughts and rambles about your favourite framework."
                    };
                    api.PostTypes.Add(type);
                    api.SaveChanges();
                }

                // Page type
                var pageType = api.PageTypes.GetSingle(@where: t => t.Slug == "standard");
                if (pageType == null)
                {
                    pageType = new Piranha.Models.PageType()
                    {
                        Name = "Standard"
                    };
                    api.PageTypes.Add(pageType);
                    api.SaveChanges();
                }

                // Categories
                var cat = api.Categories.GetSingle(@where: c => c.Slug == "development");
                if (cat == null)
                {
                    cat = new Piranha.Models.Category()
                    {
                        Title = "Development"
                    };
                    api.Categories.Add(cat);
                    api.SaveChanges();
                }

                // Posts
                var post = api.Posts.GetSingle(@where: p => p.Slug == "my-first-post");
                if (post == null)
                {
                    post = new Piranha.Models.Post()
                    {
                        AuthorId    = author.Id,
                        TypeId      = type.Id,
                        Title       = "My first post",
                        Keywords    = "Piranha CMS, Blog, First",
                        Description = "The first post of the blog",
                        Excerpt     = "Maecenas faucibus mollis interdum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.",
                        Body        = "<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam porta sem malesuada magna mollis euismod. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam quis risus eget urna mollis ornare vel eu leo.</p>" +
                                      "<p>Curabitur blandit tempus porttitor. Cras mattis consectetur purus sit amet fermentum. Aenean lacinia bibendum nulla sed consectetur. Sed posuere consectetur est at lobortis. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Vestibulum id ligula porta felis euismod semper.</p>",
                        Published = DateTime.Now
                    };

                    post.Categories.Add(cat);

                    api.Posts.Add(post);
                    api.SaveChanges();

                    api.Comments.Add(new Piranha.Models.Comment()
                    {
                        PostId     = post.Id,
                        Author     = "Håkan Edling",
                        Email      = "*****@*****.**",
                        IsApproved = true,
                        WebSite    = "http://piranhacms.org",
                        Body       = "I hope you enjoy this new version of Piranha CMS. Remember to give me your feedback at the GitHub repo."
                    });
                    api.SaveChanges();
                }

                // Pages
                var page = api.Pages.GetSingle(@where: p => p.Slug == "welcome-to-piranha-cms");
                if (page == null)
                {
                    // Get startpage body from resource file
                    string body;
                    using (var reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\App_Data\Import\startcontent.html")) {
                        body = reader.ReadToEnd();
                    }

                    // Create page
                    page = new Piranha.Models.Page()
                    {
                        AuthorId    = author.Id,
                        TypeId      = pageType.Id,
                        Title       = "Welcome to Piranha vNext",
                        IsHidden    = true,
                        Keywords    = "Piranha CMS, CMS, ASP.NET MVC, ASP.NET WebPages, Entity Framework",
                        Description = "Piranha is the fun, fast and lightweight .NET framework for developing cms-based web applications with an extra bite. It's built on ASP.NET MVC 5, Web Pages 3 & Entity Framework 6",
                        Body        = body,
                        Published   = DateTime.Now
                    };
                    api.Pages.Add(page);
                    api.SaveChanges();
                }
            }
            #endregion
        }
コード例 #5
0
ファイル: UI.cs プロジェクト: rkmr/Piranha.vNext
 /// <summary>
 /// Renders the permalink for the given post.
 /// </summary>
 /// <param name="post">The post</param>
 /// <returns>The generated permalink</returns>
 public static IHtmlString Permalink(Piranha.Models.Post post)
 {
     return(new HtmlString(helper.Permalink(post)));
 }
コード例 #6
0
ファイル: Global.asax.cs プロジェクト: cdie/Piranha.vNext
		/// <summary>
		/// Starts the MVC application.
		/// </summary>
		protected void Application_Start() {
			RouteConfig.RegisterRoutes(RouteTable.Routes);
			AreaRegistration.RegisterAllAreas();

			// Initialize the application instance with the ASP.NET runtime
			Piranha.App.Init(c => {
				c.Cache = new Piranha.AspNet.Cache.HttpCache();
				c.Env = new Piranha.AspNet.Env();
				c.Mail = new Piranha.AspNet.Mail.SmtpMail();
				c.Security = new Piranha.AspNet.Security.SimpleSecurity("admin", "password");
				c.Store = new Piranha.EntityFramework.Store();
			});

			#region Seed test data
			//
			// Let's get some default data going
			//
			using (var api = new Piranha.Api()) {
				// Only seed if we don't have any authors
				var seed = !api.Authors.Get().Any();

				if (!seed) return;
				var author = api.Authors.GetSingle(@where: a => a.Name == "Håkan Edling");
				if (author == null) {
					author = new Piranha.Models.Author() {
						Name = "Håkan Edling",
						Email = "*****@*****.**"
					};
					api.Authors.Add(author);
					api.SaveChanges();
				}

				// Post type
				var type = api.PostTypes.GetSingle(@where: t => t.Slug == "blog");
				if (type == null) {
					type = new Piranha.Models.PostType() {
						Name = "Blog post",
						EnableArchive = true,
						ArchiveTitle = "Blog",
						Slug = "blog",
						MetaKeywords = "Piranha CMS, .NET, MVC, CMS, Blog",
						MetaDescription = "Read the latest toughts and rambles about your favourite framework."
					};
					api.PostTypes.Add(type);
					api.SaveChanges();
				}

				// Page type
				var pageType = api.PageTypes.GetSingle(@where: t => t.Slug == "standard");
				if (pageType == null) {
					pageType = new Piranha.Models.PageType() {
						Name = "Standard"
					};
					api.PageTypes.Add(pageType);
					api.SaveChanges();
				}

				// Categories
				var cat = api.Categories.GetSingle(@where: c => c.Slug == "development");
				if (cat == null) {
					cat = new Piranha.Models.Category() {
						Title = "Development"
					};
					api.Categories.Add(cat);
					api.SaveChanges();
				}

				// Posts
				var post = api.Posts.GetSingle(@where: p => p.Slug == "my-first-post");
				if (post == null) {
					post = new Piranha.Models.Post() {
						AuthorId = author.Id,
						TypeId = type.Id,
						Title = "My first post",
						Keywords = "Piranha CMS, Blog, First",
						Description = "The first post of the blog",
						Excerpt = "Maecenas faucibus mollis interdum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.",
						Body = "<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam porta sem malesuada magna mollis euismod. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam quis risus eget urna mollis ornare vel eu leo.</p>" +
							   "<p>Curabitur blandit tempus porttitor. Cras mattis consectetur purus sit amet fermentum. Aenean lacinia bibendum nulla sed consectetur. Sed posuere consectetur est at lobortis. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Vestibulum id ligula porta felis euismod semper.</p>",
						Published = DateTime.Now
					};

					post.Categories.Add(cat);

					api.Posts.Add(post);
					api.SaveChanges();

					api.Comments.Add(new Piranha.Models.Comment() {
						PostId = post.Id,
						Author = "Håkan Edling",
						Email = "*****@*****.**",
						IsApproved = true,
						WebSite = "http://piranhacms.org",
						Body = "I hope you enjoy this new version of Piranha CMS. Remember to give me your feedback at the GitHub repo."
					});
					api.SaveChanges();
				}

				// Pages
				var page = api.Pages.GetSingle(@where: p => p.Slug == "welcome-to-piranha-cms");
				if (page == null) {
					// Get startpage body from resource file
					string body;
					using (var reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\App_Data\Import\startcontent.html")) {
						body = reader.ReadToEnd();
					}

					// Create page
					page = new Piranha.Models.Page() {
						AuthorId = author.Id,
						TypeId = pageType.Id,
						Title = "Welcome to Piranha vNext",
						IsHidden = true,
						Keywords = "Piranha CMS, CMS, ASP.NET MVC, ASP.NET WebPages, Entity Framework",
						Description = "Piranha is the fun, fast and lightweight .NET framework for developing cms-based web applications with an extra bite. It's built on ASP.NET MVC 5, Web Pages 3 & Entity Framework 6",
						Body = body,
						Published = DateTime.Now
					};
					api.Pages.Add(page);
					api.SaveChanges();
				}
			}
			#endregion
		}