mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-29 20:22:32 +00:00
Fix error when slot on case does not exist
This commit is contained in:
parent
f0a9fc324f
commit
643b00512a
2 changed files with 14 additions and 8 deletions
|
@ -40,14 +40,20 @@
|
|||
|
||||
@if (Model.Type.AffectsLevel())
|
||||
{
|
||||
Slot slot = await Model.GetSlotAsync(database);
|
||||
Slot? slot = await Model.GetSlotAsync(database);
|
||||
if (slot != null)
|
||||
{
|
||||
<p><strong>Affected level:</strong> <a href="/slot/@slot.SlotId">@slot.Name</a></p>
|
||||
}
|
||||
}
|
||||
else if (Model.Type.AffectsUser())
|
||||
{
|
||||
User user = await Model.GetUserAsync(database);
|
||||
User? user = await Model.GetUserAsync(database);
|
||||
if (user != null)
|
||||
{
|
||||
<p><strong>Affected user:</strong> <a href="/user/@user.UserId">@user.Username</a></p>
|
||||
}
|
||||
}
|
||||
|
||||
<h3>Reason</h3>
|
||||
@if (!string.IsNullOrWhiteSpace(Model.Reason))
|
||||
|
|
|
@ -42,16 +42,16 @@ public class ModerationCase
|
|||
public int AffectedId { get; set; }
|
||||
|
||||
#region Get affected id result
|
||||
public Task<User> GetUserAsync(Database database)
|
||||
public Task<User?> GetUserAsync(Database database)
|
||||
{
|
||||
Debug.Assert(this.Type.AffectsUser());
|
||||
return database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId)!;
|
||||
return database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId);
|
||||
}
|
||||
|
||||
public Task<Slot> GetSlotAsync(Database database)
|
||||
public Task<Slot?> GetSlotAsync(Database database)
|
||||
{
|
||||
Debug.Assert(this.Type.AffectsLevel());
|
||||
return database.Slots.FirstOrDefaultAsync(u => u.SlotId == this.AffectedId)!;
|
||||
return database.Slots.FirstOrDefaultAsync(u => u.SlotId == this.AffectedId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue