/// <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; }
/// <summary> /// Saves the current edit model. /// </summary> public void Save(Api api) { var newModel = false; // Get or create category var category = Id.HasValue ? api.Categories.GetSingle(Id.Value) : null; if (category == null) { category = new Piranha.Models.Category(); newModel = true; } // Map values Mapper.Map<EditModel, Piranha.Models.Category>(this, category); if (newModel) api.Categories.Add(category); api.SaveChanges(); this.Id = category.Id; }
/// <summary> /// Seeds some test data. /// </summary> /// <param name="db"></param> private void Seed(IApi api, Piranha.EF.Db db) { if (api.Categories.Get().Count == 0) { // Add the startpage using (var stream = File.OpenRead("assets/seed/startpage.md")) { using (var reader = new StreamReader(stream)) { var startPage = Models.ContentPageModel.Create("Content"); startPage.Title = "Welcome to Piranha CMS"; startPage.Ingress = "The CMS framework with an extra bite"; startPage.Body = reader.ReadToEnd(); startPage.Published = DateTime.Now; api.Pages.Save(startPage); } } // Add the blog category var category = new Piranha.Models.Category() { Id = Guid.NewGuid(), Title = "Blog", ArchiveTitle = "Blog Archive" }; api.Categories.Save(category); // Add a post var post = new Piranha.EF.Data.Post() { CategoryId = category.Id, Title = "My first post", Excerpt = "Etiam porta sem malesuada magna mollis euismod.", Body = "<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>", Published = DateTime.Now }; db.Posts.Add(post); db.SaveChanges(); } }
/// <summary> /// Saves the current edit model. /// </summary> public void Save(Api api) { var newModel = false; // Get or create category var category = Id.HasValue ? api.Categories.GetSingle(Id.Value) : null; if (category == null) { category = new Piranha.Models.Category(); newModel = true; } // Map values Mapper.Map <EditModel, Piranha.Models.Category>(this, category); if (newModel) { api.Categories.Add(category); } api.SaveChanges(); this.Id = category.Id; }
/// <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; }
/// <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 }
/// <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 }