Skip to content

Commit

Permalink
Feature/fixes3 (#41)
Browse files Browse the repository at this point in the history
* remove DbContextFactory
* header update
* PostDescriptionNotRequired
  • Loading branch information
petervandenhout authored Aug 11, 2019
1 parent 505c1f9 commit 83bcdfc
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 67 deletions.
4 changes: 2 additions & 2 deletions samples/Opw.PineBlog.Sample/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ConnectionStrings": {
//"DefaultConnection": "Server=.\\SQLEXPRESS; Database=pineblog-db; Trusted_Connection=True;",
"DefaultConnection": "Server=inMemory; Database=pineblog-db;"
"DefaultConnection": "Server=.\\SQLEXPRESS; Database=pineblog-db; Trusted_Connection=True;",
//"DefaultConnection": "Server=inMemory; Database=pineblog-db;"
},
"PineBlogOptions": {
"Title": "PineBlog",
Expand Down
35 changes: 0 additions & 35 deletions src/Opw.EntityFrameworkCore/DbContextFactory.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
using Microsoft.Extensions.Configuration;
using Opw.EntityFrameworkCore;
using System;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;

namespace Opw.PineBlog.EntityFrameworkCore
{
[Obsolete("This class is needed to run \"dotnet ef...\" commands from command line on development. Do not use directly.")]
public class BlogEntityDbContextFactory : DbContextFactory, IDesignTimeDbContextFactory<BlogEntityDbContext>
public class BlogEntityDbContextFactory : IDesignTimeDbContextFactory<BlogEntityDbContext>
{
public BlogEntityDbContext CreateDbContext(string[] args)
{
Expand All @@ -18,5 +21,24 @@ public BlogEntityDbContext CreateDbContext(string[] args)

return new BlogEntityDbContext(builder.Options);
}

private IConfiguration GetConfiguration()
{
var projectDir = GetApplicationRoot();
var builder = new ConfigurationBuilder()
.SetBasePath(projectDir)
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();

return builder.Build();
}

private string GetApplicationRoot()
{
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
var regex = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)");
var appRoot = regex.Match(path).Value;
return appRoot;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Configure(EntityTypeBuilder<Post> builder)

builder.Property(e => e.Title).HasMaxLength(160).IsRequired();
builder.Property(e => e.Slug).HasMaxLength(160).IsRequired();
builder.Property(e => e.Description).HasMaxLength(450).IsRequired();
builder.Property(e => e.Description).HasMaxLength(450);
builder.Property(e => e.Categories).HasMaxLength(2000);
builder.Property(e => e.Content).IsRequired();
builder.Property(e => e.CoverUrl).HasMaxLength(254);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace Opw.PineBlog.EntityFrameworkCore.Migrations
{
public partial class PostDescriptionNotRequired : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "PineBlog_Posts",
maxLength: 450,
nullable: true,
oldClrType: typeof(string),
oldMaxLength: 450);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "PineBlog_Posts",
maxLength: 450,
nullable: false,
oldClrType: typeof(string),
oldMaxLength: 450,
oldNullable: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTime>("Created");

b.Property<string>("Description")
.IsRequired()
.HasMaxLength(450);

b.Property<DateTime>("Modified");
Expand Down
3 changes: 1 addition & 2 deletions src/Opw.PineBlog.EntityFrameworkCore/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=.\\SQLEXPRESS; Database=pineblog-sqldb; Trusted_Connection=True;"
//"DefaultConnection": "Server=inMemory; Database=pineblog-db;"
"DefaultConnection": "Server=.\\SQLEXPRESS; Database=pineblog-db; Trusted_Connection=True;"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Opw.PineBlog.Posts;

namespace Opw.PineBlog.RazorPages.Areas.Admin.Pages
Expand Down Expand Up @@ -39,6 +38,7 @@ public async Task<IActionResult> OnPostAsync(CancellationToken cancellationToken
var result = await _mediator.Send(Post, cancellationToken);
if (!result.IsSuccess)
{
Logger.LogError(result.Exception, "Could not add post.");
Post.UserName = null;
ModelState.AddModelError("", result.Exception.Message);
return Page();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Opw.PineBlog.Posts;

namespace Opw.PineBlog.RazorPages.Areas.Admin.Pages
Expand Down Expand Up @@ -51,7 +50,10 @@ public async Task<IActionResult> OnPostAsync(CancellationToken cancellationToken

var result = await _mediator.Send(Post, cancellationToken);
if (!result.IsSuccess)
{
Logger.LogError(result.Exception, "Could not update post.");
ModelState.AddModelError("", result.Exception.Message);
}

return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="nav ml-auto my-auto">
@*<ul class="nav ml-auto my-auto">
<li class="nav-item">
<a class="nav-link" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
</ul>
</ul>*@
</div>
@*@if (showSearch)
{
Expand All @@ -27,4 +27,4 @@
</button>
}*@
</div>
</header>
</header>
24 changes: 4 additions & 20 deletions src/Opw.PineBlog.RazorPages/wwwroot/themes/default/blog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ h4, h5, h6 {
}

.page-content {
padding-top: 1rem;
padding-bottom: 1rem;
}
padding-top: 2rem;
padding-bottom: 2rem;

@media screen and (min-width: 992px) {
.page-content {
@media screen and (min-width: 992px) {
padding-top: 5rem;
padding-bottom: 5rem;
}
Expand Down Expand Up @@ -226,32 +224,18 @@ h4, h5, h6 {
.footer {
color: #f7f7f7;
font-size: .75rem;
padding: 2rem 0 1.8rem 0;
background-color: #222;

h2 {
font-size: 1.2rem;
font-weight: normal;
}

img {
border: 1px solid #f7f7f7;
max-width: 15%;
float: left;
margin: 0.25rem 1rem 0 0;
}

a {
color: #fff;
}

p {
margin: 0;
}

&.copy {
background-color: #000;
padding: 1rem 0;
padding-bottom: 1.5rem;
font-size: .65rem;

.container {
Expand Down

0 comments on commit 83bcdfc

Please sign in to comment.