Skip to content

Commit

Permalink
Platform: fix possible null references
Browse files Browse the repository at this point in the history
  • Loading branch information
yelizsevinc committed Aug 7, 2024
1 parent d3ec9ed commit 5cea8f1
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions CineStream/Components/Pages/Platform/PlatformDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@
<CardText>
@if (platformShows != null)
{
@foreach (var show in platformShows)
{
<ul>
<li class=my-1>
<Button Icon="times" Variant="Danger" OnClick="@(e => RemoveShow(show.Title))"></Button> @show.Title
</li>
</ul>
}
<ul>
@foreach (var show in platformShows)
{
@if (show.Title != null)
{
<li class=my-1>
<Button Icon="times" Variant="Danger" OnClick="@(e => RemoveShow(show.Title))"></Button>
@show.Title
</li>
}
}
</ul>
}
</CardText>
</CardBlock>
Expand All @@ -74,14 +78,18 @@
<CardText>
@if (platformUsers != null)
{
@foreach (var user in platformUsers)
{
<ul>
<li class=my-1>
<Button Icon="times" Variant="Danger" OnClick="@(e => RemoveUser(user.Username))"></Button> @user.Username
</li>
</ul>
}
<ul>
@foreach (var user in platformUsers)
{
@if (user.Username != null)
{
<li class=my-1>
<Button Icon="times" Variant="Danger"
OnClick="@(e => RemoveUser(user.Username))"></Button> @user.Username
</li>
}
}
</ul>
}
</CardText>
</CardBlock>
Expand Down Expand Up @@ -185,6 +193,8 @@

private async Task DeletePlatformAsync()
{
if (platform == null) return;

try
{
using var context = await DbFactory.CreateDbContextAsync();
Expand All @@ -210,7 +220,10 @@
// Remove show from platform
using var context = await DbFactory.CreateDbContextAsync();
var show = await context.Shows!.FirstOrDefaultAsync(c => c.Title == showTitle);
var platformShow = await context.PlatformShows!.FirstOrDefaultAsync(c => c.ShowId == show.ShowId && c.PlatformId == platform.PlatformId);
if (show == null || platform == null) return;
var platformShow = await context.PlatformShows!.FirstOrDefaultAsync(c => c.ShowId == show.ShowId && c.PlatformId ==
platform.PlatformId);
if (platformShow == null) return;
context.PlatformShows!.Remove(platformShow);
await context.SaveChangesAsync();
// Reload platform shows
Expand All @@ -224,7 +237,10 @@
// Remove user from platform
using var context = await DbFactory.CreateDbContextAsync();
var user = await context.Users!.FirstOrDefaultAsync(c => c.Username == username);
var platformUser = await context.PlatformUsers!.FirstOrDefaultAsync(c => c.UserId == user.UserId && c.PlatformId == platform.PlatformId);
if (user == null || platform == null) return;
var platformUser = await context.PlatformUsers!.FirstOrDefaultAsync(c => c.UserId == user.UserId && c.PlatformId ==
platform.PlatformId);
if (platformUser == null) return;
context.PlatformUsers!.Remove(platformUser);
await context.SaveChangesAsync();
// Reload platform users
Expand Down

0 comments on commit 5cea8f1

Please sign in to comment.