Added database loading logic
This commit is contained in:
@@ -8,11 +8,22 @@
|
||||
Welcome to your new Fluent Blazor app.
|
||||
|
||||
@inject IContextExplorer Explorer
|
||||
@inject DatabaseContext Context
|
||||
|
||||
@code {
|
||||
|
||||
protected override void OnInitialized() {
|
||||
Console.WriteLine(string.Join(", ", Explorer.GetTableNames()));
|
||||
protected override async Task OnInitializedAsync() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Context.Users.Add(new() {
|
||||
Email = "leon@ladenbau-hoppe.de",
|
||||
Id = Guid.CreateVersion7()
|
||||
});
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
var manager = Explorer.GetTableManager("Users");
|
||||
var page = await manager!.LoadPage(0);
|
||||
Console.WriteLine(string.Join(", ", page));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,5 +6,13 @@ namespace HopFrame.Testing;
|
||||
public class DatabaseContext(DbContextOptions<DatabaseContext> options) : DbContext(options) {
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
public DbSet<Post> Posts { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder) {
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Post>()
|
||||
.HasOne<User>()
|
||||
.WithMany();
|
||||
}
|
||||
}
|
||||
17
testing/HopFrame.Testing/Models/Post.cs
Normal file
17
testing/HopFrame.Testing/Models/Post.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace HopFrame.Testing.Models;
|
||||
|
||||
public class Post {
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[MaxLength(255)]
|
||||
public required string Caption { get; set; }
|
||||
|
||||
public required string Content { get; set; }
|
||||
|
||||
[ForeignKey("author")]
|
||||
public User? Author { get; set; }
|
||||
}
|
||||
@@ -7,4 +7,8 @@ public class User {
|
||||
public string? Password { get; set; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
|
||||
public override string ToString() {
|
||||
return Id.ToString();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using HopFrame.Core.Services;
|
||||
using HopFrame.Testing;
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
using HopFrame.Testing.Components;
|
||||
using HopFrame.Testing.Services;
|
||||
using HopFrame.Web;
|
||||
using HopFrame.Web.Components.Pages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -17,10 +19,12 @@ builder.Services.AddDbContext<DatabaseContext>(options => {
|
||||
});
|
||||
|
||||
builder.Services.AddHopFrame(options => {
|
||||
options.DisplayUserInfo(false);
|
||||
options.SetAuthHandler<AuthService>();
|
||||
options.AddDbContext<DatabaseContext>();
|
||||
});
|
||||
|
||||
builder.Services.AddTransient<IHopFrameAuthHandler, AuthService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
12
testing/HopFrame.Testing/Services/AuthService.cs
Normal file
12
testing/HopFrame.Testing/Services/AuthService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using HopFrame.Core.Services;
|
||||
|
||||
namespace HopFrame.Testing.Services;
|
||||
|
||||
public class AuthService : IHopFrameAuthHandler {
|
||||
public Task<bool> IsAuthenticatedAsync(string? policy) {
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
public Task<string> GetCurrentUserDisplayNameAsync() {
|
||||
return Task.FromResult("Leon Hoppe");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user