Init data, single home page, multi-tenant
This commit is contained in:
14
src/MyWebLog.Data/Extensions/PageExtensions.cs
Normal file
14
src/MyWebLog.Data/Extensions/PageExtensions.cs
Normal 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);
|
||||
}
|
||||
17
src/MyWebLog.Data/Extensions/PostExtensions.cs
Normal file
17
src/MyWebLog.Data/Extensions/PostExtensions.cs
Normal 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();
|
||||
}
|
||||
14
src/MyWebLog.Data/Extensions/WebLogDetailsExtensions.cs
Normal file
14
src/MyWebLog.Data/Extensions/WebLogDetailsExtensions.cs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user