Init data, single home page, multi-tenant

This commit is contained in:
2022-02-27 12:38:08 -05:00
parent 8bc2cf0aa5
commit df3467030a
32 changed files with 2012 additions and 651 deletions

View File

@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore;
namespace MyWebLog.Data;
public static class PageExtensions
{
/// <summary>
/// Retrieve a page by its ID (non-tracked)
/// </summary>
/// <param name="id">The ID of the page to retrieve</param>
/// <returns>The requested page (or null if it is not found)</returns>
public static async Task<Page?> FindById(this DbSet<Page> db, string id) =>
await db.FirstOrDefaultAsync(p => p.Id == id).ConfigureAwait(false);
}

View File

@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
namespace MyWebLog.Data;
public static class PostExtensions
{
/// <summary>
/// Retrieve a page of published posts (non-tracked)
/// </summary>
/// <param name="pageNbr">The page number to retrieve</param>
/// <param name="postsPerPage">The number of posts per page</param>
/// <returns>A list of posts representing the posts for the given page</returns>
public static async Task<List<Post>> FindPageOfPublishedPosts(this DbSet<Post> db, int pageNbr, int postsPerPage) =>
await db.Where(p => p.Status == PostStatus.Published)
.Skip((pageNbr - 1) * postsPerPage).Take(postsPerPage)
.ToListAsync();
}

View File

@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore;
namespace MyWebLog.Data;
public static class WebLogDetailsExtensions
{
/// <summary>
/// Find the details of a web log by its host
/// </summary>
/// <param name="host">The host</param>
/// <returns>The web log (or null if not found)</returns>
public static async Task<WebLogDetails?> FindByHost(this DbSet<WebLogDetails> db, string host) =>
await db.FirstOrDefaultAsync(wld => wld.UrlBase == host).ConfigureAwait(false);
}