protected override void Init() { using (var api = CreateApi()) { // Import content types new PageTypeBuilder(api) .AddType(typeof(BlogArchive)) .Build(); new PostTypeBuilder(api) .AddType(typeof(BlogPost)) .Build(); // Add site var site = new Site() { Id = SITE_ID, Title = "Comment Site", InternalId = "CommentSite", IsDefault = true }; api.Sites.Save(site); // Add archive var blog = BlogArchive.Create(api); blog.Id = BLOG_ID; blog.SiteId = SITE_ID; blog.Title = "Blog"; blog.EnableComments = true; blog.Published = DateTime.Now; api.Pages.Save(blog); var news = BlogArchive.Create(api); news.Id = NEWS_ID; news.SiteId = SITE_ID; news.Title = "News"; blog.EnableComments = true; news.Published = DateTime.Now; api.Pages.Save(news); // Add posts var blogPost = BlogPost.Create(api); blogPost.Id = BLOGPOST_ID; blogPost.BlogId = BLOG_ID; blogPost.Category = "The Category"; blogPost.Title = "Welcome To The Blog"; blogPost.Published = DateTime.Now; api.Posts.Save(blogPost); var newsPost = BlogPost.Create(api); newsPost.Id = NEWSPOST_ID; newsPost.BlogId = NEWS_ID; newsPost.Category = "The Category"; newsPost.Title = "Welcome To The News"; newsPost.Published = DateTime.Now; api.Posts.Save(newsPost); } }
public void Given_builder_is_null_When_Create_is_called_Then_a_ArgumentNullException_should_be_thrown() { // Given. BlogPost blogPost; BlogPostBuilder builder = null; // When. Action action = () => blogPost = BlogPost.Create(builder); // Then. action.Should().Throw <ArgumentNullException>() .WithMessage("*cannot be null*builder*"); }
public void LoadsSameInstanceWhenUsingFindByID() { // Arrange. var post = BlogPost.Create(new BlogPost { DatePublished = DateTime.Now, Title = "My Blog Post", Text = "Some text" }); // Act. var result = BlogPost.Find(post.ID); // Assert. Assert.That(ReferenceEquals(post, result), Is.True); }
public void LoadsSameInstanceWhenUsingFindWithQuery() { // Arrange. var post1 = BlogPost.Create(new BlogPost { DatePublished = DateTime.Now, Title = "My Blog Post 1", Text = "Some text" }); BlogPost.Create(new BlogPost { DatePublished = DateTime.Now, Title = "My Blog Post 2", Text = "Some text" }); // Act. var result = BlogPost.All().ToList(); // Assert. Assert.That(ReferenceEquals(post1, result[0]), Is.True); }
public async Task <APIGatewayProxyResponse> Post(APIGatewayProxyRequest proxyRequest) { var statusCode = (proxyRequest != null) ? HttpStatusCode.OK : HttpStatusCode.BadRequest; var(request, requestError) = proxyRequest.Body.Deserialize <CreatePostRequest>(); if (requestError != null) { statusCode = HttpStatusCode.BadRequest; } var(post, postError) = BlogPost.Create(new PostId(Guid.NewGuid()), request.Category, request.Title, request.Content); if (postError != null) { statusCode = HttpStatusCode.BadRequest; } var(result, message) = await _postRepository.Save(post); var response = new APIGatewayProxyResponse() { StatusCode = (int)result, Headers = new Dictionary <string, string> { { "Access-Control-Allow-Origin", "*" }, { "Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accepted" }, { "Content-Type", "application/json" } }, Body = message.ToJson() }; return(response); }
public async Task <IActionResult> Seed() { // Get the default site var site = await _api.Sites.GetDefaultAsync(); site.SiteTypeId = nameof(BlogSite); await _api.Sites.SaveAsync(site); // Add media assets var bannerId = Guid.NewGuid(); using (var stream = System.IO.File.OpenRead("seed/pexels-photo-355423.jpeg")) { await _api.Media.SaveAsync(new Piranha.Models.StreamMediaContent() { Id = bannerId, Filename = "pexels-photo-355423.jpeg", Data = stream }); } var banner = await _api.Media.GetByIdAsync(bannerId); var logoId = Guid.NewGuid(); using (var stream = System.IO.File.OpenRead("seed/logo.png")) { await _api.Media.SaveAsync(new Piranha.Models.StreamMediaContent() { Id = logoId, Filename = "logo.png", Data = stream }); } // Add the site info var blogSite = BlogSite.Create(_api); blogSite.Information.SiteLogo = logoId; blogSite.Information.SiteTitle = "Piranha CMS"; blogSite.Information.Tagline = "A lightweight & unobtrusive CMS for Asp.NET Core."; await _api.Sites.SaveContentAsync(site.Id, blogSite); // Add the blog archive var blogId = Guid.NewGuid(); var blogPage = BlogArchive.Create(_api); blogPage.Id = blogId; blogPage.SiteId = site.Id; blogPage.Title = "Blog Archive"; blogPage.MetaKeywords = "Inceptos, Tristique, Pellentesque, Lorem, Vestibulum"; blogPage.MetaDescription = "Morbi leo risus, porta ac consectetur ac, vestibulum at eros."; blogPage.NavigationTitle = "Blog"; blogPage.Published = DateTime.Now; await _api.Pages.SaveAsync(blogPage); // Add a blog post var post = BlogPost.Create(_api); post.BlogId = blogPage.Id; post.Category = "Piranha CMS"; post.Tags.Add("Welcome", "Fresh Start", "Information"); post.Title = "Welcome to Piranha CMS!"; post.MetaKeywords = "Welcome, Piranha CMS, AspNetCore, MVC, .NET Core"; post.MetaDescription = "Piranha is the fun, fast and lightweight framework for developing cms-based web applications with ASP.Net Core."; post.Hero.PrimaryImage = bannerId; post.Hero.Ingress = "<p>Piranha CMS is a <strong>lightweight</strong>, <strong>cross-platform</strong> CMS <string>library</string> for <code>NetStandard 2.0</code>, <code>.NET Core</code> & <code>Entity Framework Core</code>. It can be used to add CMS functionality to your existing application or to build a new website from scratch. It has an extensible & pluggable architecture that can support a wide variety of runtime scenarios.</p>"; post.Blocks.Add(new HtmlBlock { Body = "<p>Piranha CMS is a <strong>lightweight</strong>, <strong>cross-platform</strong> CMS <string>library</string> for <code>NetStandard 2.0</code>, <code>.NET Core</code> & <code>Entity Framework Core</code>. It can be used to add CMS functionality to your existing application or to build a new website from scratch. It has an extensible & pluggable architecture that can support a wide variety of runtime scenarios.</p><p>Piranha CMS is totally <strong>package based</strong> and available on <code>NuGet</code>. You can read more about the different packages available in the documentation.</p>" }); post.Blocks.Add(new HtmlBlock { Body = "<h2>Getting Started</h2><p>To log into the manager interface and start writing content simply go the URL <code>/manager</code> and login with <code>admin</code> / <code>password</code> as your username and password.</p>" }); post.Blocks.Add(new HtmlBlock { Body = "<h2>Licensing</h2><p>Piranha CMS is released under the <strong>MIT</strong> license. It is a permissive free software license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms and the copyright notice.</p>" }); post.Published = DateTime.Now; await _api.Posts.SaveAsync(post); // Add about page var page = StandardPage.Create(_api); page.SiteId = site.Id; page.SortOrder = 1; page.Title = "About Me"; page.MetaKeywords = "Inceptos, Tristique, Pellentesque, Lorem, Vestibulum"; page.MetaDescription = "Morbi leo risus, porta ac consectetur ac, vestibulum at eros."; page.Blocks.Add(new HtmlBlock { Body = "<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Vestibulum id ligula porta felis euismod semper. Nulla vitae elit libero, a pharetra augue. Donec id elit non mi porta gravida at eget metus. Donec ullamcorper nulla non metus auctor fringilla.</p>" }); page.Blocks.Add(new QuoteBlock { Body = "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod." }); page.Blocks.Add(new ColumnBlock { Items = new List <Block> { new HtmlBlock { Body = $"<p><img src=\"{banner.PublicUrl.Replace("~", "")}\"></p>" }, new HtmlBlock { Body = "<p>Maecenas faucibus mollis interdum. Aenean lacinia bibendum nulla sed consectetur. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.</p>" } } }); page.Published = DateTime.Now; await _api.Pages.SaveAsync(page); return(Redirect("~/")); }
public async Task <IActionResult> Seed() { // Get the default site var site = await _api.Sites.GetDefaultAsync(); // Add media assets var bannerId = Guid.NewGuid(); using (var stream = System.IO.File.OpenRead("seed/pexels-photo-355423.jpeg")) { await _api.Media.SaveAsync(new Piranha.Models.StreamMediaContent() { Id = bannerId, Filename = "pexels-photo-355423.jpeg", Data = stream }); } // Add the blog archived var blogId = Guid.NewGuid(); var blogPage = BlogArchive.Create(_api); blogPage.Id = blogId; blogPage.SiteId = site.Id; blogPage.Title = "Blog Archive"; blogPage.MetaKeywords = " software, website ,appdev,appbuider,backend"; blogPage.MetaDescription = "software through to the finalt includes all that is involved between."; blogPage.NavigationTitle = "Blog"; blogPage.Hero.PrimaryImage = bannerId; blogPage.Hero.Ingress = "software through to the finalt includes all that is involved between."; blogPage.Published = DateTime.Now; await _api.Pages.SaveAsync(blogPage); // Add a blog post var postId = Guid.NewGuid(); var post = BlogPost.Create(_api); post.Id = postId; post.BlogId = blogPage.Id; post.Category = "Software"; post.Tags.Add("Software develepement", "Machine Learning", "Technologies"); post.Title = "Software developement"; post.MetaKeywords = " software, website ,appdev,appbuider,backend"; post.MetaDescription = "software through to the finalt includes all that is involved between."; post.Hero.PrimaryImage = bannerId; post.Hero.Ingress = " Software through to the final manifestation of the software it includes all that is involved between."; post.Blocks.Add(new HtmlBlock { Body = "<p>it includes all that is involved between the conception of the desired software through to the final manifestation of the software it includes all that is involved between the conception of the desired software through to the final manifestation of the software.</p>" }); post.Published = DateTime.Now; await _api.Posts.SaveAsync(post); // Add the startpage var startPage = StartPage.Create(_api); startPage.SiteId = site.Id; startPage.Title = "Machine Learning"; startPage.MetaKeywords = "Software,webdev,machine learning, technologies, web"; startPage.MetaDescription = "software through to the finalt includes all that is involved between."; startPage.NavigationTitle = "Home"; startPage.Hero.PrimaryImage = bannerId; startPage.Hero.Ingress = "software through to the finalt includes all that is involved between."; startPage.Blocks.Add(new HtmlBlock { Body = "<p>Software development is the process of conceiving, specifying, designing, programming, documenting, testing, and bug fixing involved in creating and maintaining applications, frameworks, or other software components..</p>" }); startPage.Published = DateTime.Now; // Add teasers startPage.Teasers.Add(new Teaser() { Title = "Software Prod", SubTitle = "Software staging", Body = "Software development is a process of writing and maintaining the source code, but in a broader sense,.", PageLink = blogPage }); startPage.Teasers.Add(new Teaser() { Title = "Sftware in Practice", SubTitle = "Software Dev", Body = "Tt includes all that is involved between the conception of the desired software through to the final manifestation of the software.", PostLink = post }); await _api.Pages.SaveAsync(startPage); return(Redirect("~/")); }
public async Task <IActionResult> Seed() { // Get the default site var site = await api.Sites.GetDefaultAsync(); // Add media assets var bannerId = Guid.NewGuid(); using (var stream = System.IO.File.OpenRead("seed/pexels-photo-355423.jpeg")) { await api.Media.SaveAsync(new Piranha.Models.StreamMediaContent() { Id = bannerId, Filename = "pexels-photo-355423.jpeg", Data = stream }); } // Add the blog archived var blogId = Guid.NewGuid(); var blogPage = BlogArchive.Create(api); blogPage.Id = blogId; blogPage.SiteId = site.Id; blogPage.Title = "Blog Archive"; blogPage.MetaKeywords = "Inceptos, Tristique, Pellentesque, Lorem, Vestibulum"; blogPage.MetaDescription = "Morbi leo risus, porta ac consectetur ac, vestibulum at eros."; blogPage.NavigationTitle = "Blog"; blogPage.Hero.Subtitle = "Morbi leo risus"; blogPage.Hero.PrimaryImage = bannerId; blogPage.Hero.Ingress = "Curabitur blandit tempus porttitor. Maecenas sed diam eget risus varius blandit sit amet non magna."; blogPage.Published = DateTime.Now; await api.Pages.SaveAsync(blogPage); // Add a blog post var postId = Guid.NewGuid(); var post = BlogPost.Create(api); post.Id = postId; post.BlogId = blogPage.Id; post.Category = "Uncategorized"; post.Tags.Add("Ornare", "Pellentesque", "Fringilla Ridiculus"); post.Title = "Dapibus Cursus Justo"; post.MetaKeywords = "Nullam, Mollis, Cras, Sem, Ipsum"; post.MetaDescription = "Aenean lacinia bibendum nulla sed consectetur."; post.Hero.Subtitle = "Morbi leo risus"; post.Hero.PrimaryImage = bannerId; post.Hero.Ingress = "Sed posuere consectetur est at lobortis. Praesent commodo cursus magna, vel scelerisque nisl consectetur et."; post.Blocks.Add(new HtmlBlock { Body = "<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Curabitur blandit tempus porttitor. Maecenas faucibus mollis interdum.</p>" }); post.Published = DateTime.Now; await api.Posts.SaveAsync(post); // Add the startpage var startPage = StartPage.Create(api); startPage.SiteId = site.Id; startPage.Title = "Porta Tortor Euismod"; startPage.MetaKeywords = "Fusce, Tristique, Nullam, Parturient, Pellentesque"; startPage.MetaDescription = "Vestibulum id ligula porta felis euismod semper."; startPage.NavigationTitle = "Home"; startPage.Hero.PrimaryImage = bannerId; startPage.Hero.Ingress = "Aenean lacinia bibendum nulla sed consectetur."; startPage.Blocks.Add(new HtmlBlock { Body = "<p>Nulla vitae elit libero, a pharetra augue. Curabitur blandit tempus porttitor. Nulla vitae elit libero, a pharetra augue. Donec id elit non mi porta gravida at eget metus. Curabitur blandit tempus porttitor.</p><p>Etiam porta sem malesuada magna mollis euismod. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Curabitur blandit tempus porttitor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>" }); startPage.Published = DateTime.Now; // Add teasers startPage.Teasers.Add(new TeaserRegion() { Title = "Lorem Consectetur", SubTitle = "Ultricies Nullam Cras", Body = "Aenean lacinia bibendum nulla sed consectetur. Donec id elit non mi porta gravida at eget metus.", PageLink = blogPage }); startPage.Teasers.Add(new TeaserRegion() { Title = "Vestibulum Bibendum", SubTitle = "Tortor Cras Tristique", Body = "Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam.", PostLink = post }); await api.Pages.SaveAsync(startPage); return(Redirect("~/")); }
public static async Task RunAsync(IApi api) { if (await api.Pages.GetStartpageAsync() == null) { var images = new dynamic[] { new { id = Guid.NewGuid(), filename = "screenshot2.png" }, new { id = Guid.NewGuid(), filename = "logo.png" }, new { id = Guid.NewGuid(), filename = "teaser1.png" }, new { id = Guid.NewGuid(), filename = "teaser2.png" }, new { id = Guid.NewGuid(), filename = "teaser3.png" } }; // Get the default site id var siteId = (await api.Sites.GetDefaultAsync()).Id; // Upload images foreach (var image in images) { using (var stream = File.OpenRead("seed/" + image.filename)) { await api.Media.SaveAsync(new StreamMediaContent { Id = image.id, Filename = image.filename, Data = stream }); } } // Create the start page var startpage = TeaserPage.Create(api); startpage.SiteId = siteId; startpage.Title = "Piranha CMS - Open Source, Cross Platform Asp.NET Core CMS"; startpage.NavigationTitle = "Home"; startpage.MetaKeywords = "Piranha, Piranha CMS, CMS, AspNetCore, DotNetCore, MVC, .NET, .NET Core"; startpage.MetaDescription = "Piranha is the fun, fast and lightweight framework for developing cms-based web applications with AspNetCore."; // Start page hero startpage.Hero.Subtitle = "By developers - for developers"; startpage.Hero.PrimaryImage = images[1].id; startpage.Hero.Ingress = "<p>A lightweight & unobtrusive CMS for ASP.NET Core.</p>" + "<p><small>Stable version 5.2.1 - 2018-10-17 - <a href=\"https://github.com/piranhacms/piranha.core/wiki/changelog\" target=\"_blank\">Changelog</a></small></p>"; // Teasers startpage.Teasers.Add(new Teaser { Title = "Cross Platform", Image = images[2].id, Body = "<p>Built for <code>NetStandard</code> and <code>AspNet Core</code>, Piranha CMS can be run on Windows, Linux and Mac OS X.</p>" }); startpage.Teasers.Add(new Teaser { Title = "Super Fast", Image = images[3].id, Body = "<p>Designed from the ground up for super-fast performance using <code>EF Core</code> and optional Caching.</p>" }); startpage.Teasers.Add(new Teaser { Title = "Open Source", Image = images[4].id, Body = "<p>Everything is Open Source and released under the <code>MIT</code> license for maximum flexibility.</p>" }); // Start page blocks startpage.Blocks.Add(new ImageBlock { Body = images[0].id }); using (var stream = File.OpenRead("seed/startpage1.md")) { using (var reader = new StreamReader(stream)) { startpage.Blocks.Add(new HtmlBlock { Body = App.Markdown.Transform(reader.ReadToEnd()) }); } } using (var stream = File.OpenRead("seed/startpage2.md")) { using (var reader = new StreamReader(stream)) { startpage.Blocks.Add(new HtmlBlock { Body = App.Markdown.Transform(reader.ReadToEnd()) }); } } startpage.Published = DateTime.Now; await api.Pages.SaveAsync(startpage); // Features page var featurespage = StandardPage.Create(api); featurespage.SiteId = siteId; featurespage.Title = "Features"; featurespage.Route = "/pagewide"; featurespage.SortOrder = 1; // Features hero featurespage.Hero.Subtitle = "Features"; featurespage.Hero.Ingress = "<p>It's all about who has the sharpest teeth in the pond.</p>"; // Features blocks using (var stream = File.OpenRead("seed/features.md")) { using (var reader = new StreamReader(stream)) { var body = reader.ReadToEnd(); foreach (var section in body.Split("%")) { var blocks = section.Split("@"); for (var n = 0; n < blocks.Length; n++) { var cols = blocks[n].Split("|"); if (cols.Length == 1) { featurespage.Blocks.Add(new HtmlBlock { Body = App.Markdown.Transform(cols[0].Trim()) }); } else { featurespage.Blocks.Add(new HtmlColumnBlock { Column1 = App.Markdown.Transform(cols[0].Trim()), Column2 = App.Markdown.Transform(cols[1].Trim()) }); if (n < blocks.Length - 1) { featurespage.Blocks.Add(new SeparatorBlock()); } } } } } } featurespage.Published = DateTime.Now; await api.Pages.SaveAsync(featurespage); // Blog Archive var blogpage = BlogArchive.Create(api); blogpage.Id = Guid.NewGuid(); blogpage.SiteId = siteId; blogpage.Title = "Blog Archive"; blogpage.NavigationTitle = "Blog"; blogpage.SortOrder = 2; blogpage.MetaKeywords = "Piranha, Piranha CMS, CMS, AspNetCore, DotNetCore, MVC, Blog, News"; blogpage.MetaDescription = "Read the latest blog posts about Piranha, fast and lightweight framework for developing cms-based web applications with AspNetCore."; // Blog Hero blogpage.Hero.Subtitle = "Blog Archive"; blogpage.Hero.Ingress = "<p>Welcome to the blog, the best place to stay up to date with what's happening in the Piranha infested waters.</p>"; blogpage.Published = DateTime.Now; await api.Pages.SaveAsync(blogpage); // Blog Post var blogpost = BlogPost.Create(api); blogpost.BlogId = blogpage.Id; blogpost.Title = "What is Piranha"; blogpost.Category = "Piranha CMS"; blogpost.Tags.Add("welcome"); using (var stream = File.OpenRead("seed/blogpost.md")) { using (var reader = new StreamReader(stream)) { var body = reader.ReadToEnd(); foreach (var block in body.Split("@")) { blogpost.Blocks.Add(new HtmlBlock { Body = App.Markdown.Transform(block.Trim()) }); } } } blogpost.Published = DateTime.Now; await api.Posts.SaveAsync(blogpost); } }