diff --git a/SpotiParty.Web/Components/Pages/EnqueuePage.razor.cs b/SpotiParty.Web/Components/Pages/EnqueuePage.razor.cs index 3ecd2d5..c26440c 100644 --- a/SpotiParty.Web/Components/Pages/EnqueuePage.razor.cs +++ b/SpotiParty.Web/Components/Pages/EnqueuePage.razor.cs @@ -32,7 +32,7 @@ public partial class EnqueuePage(AuthorizationHandler authHandler, NavigationMan } _event = await context.Events - .Include(e => e.Host) + .Include(@event => @event.Host) .FirstOrDefaultAsync(e => e.Id == guid); if (_event is null) { diff --git a/SpotiParty.Web/Migrations/DatabaseContextModelSnapshot.cs b/SpotiParty.Web/Migrations/DatabaseContextModelSnapshot.cs index 7e9fbf3..27f4f56 100644 --- a/SpotiParty.Web/Migrations/DatabaseContextModelSnapshot.cs +++ b/SpotiParty.Web/Migrations/DatabaseContextModelSnapshot.cs @@ -46,7 +46,7 @@ namespace SpotiParty.Web.Migrations b.HasIndex("host"); - b.ToTable("Events"); + b.ToTable("Events", (string)null); }); modelBuilder.Entity("SpotiParty.Web.Models.User", b => @@ -75,7 +75,7 @@ namespace SpotiParty.Web.Migrations b.HasKey("UserId"); - b.ToTable("Users"); + b.ToTable("Users", (string)null); }); modelBuilder.Entity("SpotiParty.Web.Models.Event", b => diff --git a/SpotiParty.Web/Program.cs b/SpotiParty.Web/Program.cs index 53c8539..3f5c901 100644 --- a/SpotiParty.Web/Program.cs +++ b/SpotiParty.Web/Program.cs @@ -48,8 +48,7 @@ builder.Services.AddHopFrame(config => { }); context.Table() - .SetDisplayName(Guid.NewGuid().ToString()) - .Ignore(true); + .Ignore(); }); config.AddCustomRepository(e => e.Id, table => { @@ -63,8 +62,7 @@ builder.Services.AddHopFrame(config => { table.Property(e => e.Host) .List(false) .SetEditable(false) - .SetCreatable(false) - .SetDisplayedProperty(u => u.DisplayName); + .SetCreatable(false); table.ShowSearchSuggestions(false); }); diff --git a/SpotiParty.Web/Services/DashboardAuthHandler.cs b/SpotiParty.Web/Services/DashboardAuthHandler.cs index ced6f4c..b95bc12 100644 --- a/SpotiParty.Web/Services/DashboardAuthHandler.cs +++ b/SpotiParty.Web/Services/DashboardAuthHandler.cs @@ -38,6 +38,7 @@ public class DashboardAuthHandler(ClientSideStorage storage, IDbContextFactory u.RefreshToken == token); } diff --git a/SpotiParty.Web/Services/EventsDashboardRepo.cs b/SpotiParty.Web/Services/EventsDashboardRepo.cs index 496b58e..d667294 100644 --- a/SpotiParty.Web/Services/EventsDashboardRepo.cs +++ b/SpotiParty.Web/Services/EventsDashboardRepo.cs @@ -4,14 +4,15 @@ using SpotiParty.Web.Models; namespace SpotiParty.Web.Services; -public class EventsDashboardRepo(DatabaseContext context, DashboardAuthHandler handler) : IHopFrameRepository { +public class EventsDashboardRepo(DatabaseContext context, DashboardAuthHandler handler, IDbContextFactory factory) : IHopFrameRepository { + public async Task> LoadPage(int page, int perPage) { var user = await handler.GetCurrentUser(); if (user is null) return []; return await context.Events - .AsNoTracking() .Include(e => e.Host) + .OrderBy(e => e.Id) .Where(e => e.Host.UserId == user.UserId) .Skip(page * perPage) .Take(perPage) @@ -29,12 +30,14 @@ public class EventsDashboardRepo(DatabaseContext context, DashboardAuthHandler h } public async Task CreateItem(Event item) { + await using var tempContext = await factory.CreateDbContextAsync(); + var creator = await handler.GetCurrentUser(); - context.Attach(creator!); + tempContext.Attach(creator!); item.Host = creator!; - await context.Events.AddAsync(item); - await context.SaveChangesAsync(); + await tempContext.Events.AddAsync(item); + await tempContext.SaveChangesAsync(); } public async Task EditItem(Event item) { diff --git a/SpotiParty.Web/SpotiParty.Web.csproj b/SpotiParty.Web/SpotiParty.Web.csproj index a24811a..51c82f3 100644 --- a/SpotiParty.Web/SpotiParty.Web.csproj +++ b/SpotiParty.Web/SpotiParty.Web.csproj @@ -20,7 +20,7 @@ - + all