Skip to content

Commit

Permalink
Show: implement removing platforms & users from show
Browse files Browse the repository at this point in the history
  • Loading branch information
yelizsevinc committed Aug 8, 2024
1 parent fb842fc commit 6c5a5bb
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions CineStream/Components/Pages/Show/ShowDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@
<ul>
@foreach (var platform in showPlatforms)
{
<li>@platform.Name</li>
@if (platform.Name != null)
{
<li class=my-1>
<Button Icon="times" Variant="Danger"
OnClick="@(e => RemovePlatform(platform.Name))"></Button>
@platform.Name
</li>
}
}
</ul>
}
Expand Down Expand Up @@ -72,7 +79,13 @@
<ul>
@foreach (var user in showUsers)
{
<li>@user.Username</li>
@if (user.Username != null)
{
<li class=my-1>
<Button Icon="times" Variant="Danger"
OnClick="@(e => RemoveUser(user.Username))"></Button> @user.Username
</li>
}
}
</ul>
}
Expand Down Expand Up @@ -199,4 +212,36 @@
Console.Error.WriteLine($"Error deleting show: {ex.Message}");
}
}

private async Task RemovePlatform(string showTitle)
{
// Remove platform from show
using var context = await DbFactory.CreateDbContextAsync();
var platform = await context.Platforms!.FirstOrDefaultAsync(c => c.Name == showTitle);
if (platform == null || show == null) return;
var showPlatform = await context.PlatformShows!.FirstOrDefaultAsync(c => c.PlatformId == platform.PlatformId && c.ShowId
==
show.ShowId);
if (showPlatform == null) return;
context.PlatformShows!.Remove(showPlatform);
await context.SaveChangesAsync();
// Reload show platforms
showPlatforms.Clear();
await LoadShowPlatformsAsync(context);
}

private async Task RemoveUser(string username)
{
// Remove user from show
using var context = await DbFactory.CreateDbContextAsync();
var user = await context.Users!.FirstOrDefaultAsync(c => c.Username == username);
if (user == null || show == null) return;
var showUser = await context.UserShows!.FirstOrDefaultAsync(c => c.UserId == user.UserId && c.ShowId == show.ShowId);
if (showUser == null) return;
context.UserShows!.Remove(showUser);
await context.SaveChangesAsync();
// Reload show users
showUsers.Clear();
await LoadShowUsersAsync(context);
}
}

0 comments on commit 6c5a5bb

Please sign in to comment.