Skip to content

Commit 192fb87

Browse files
authored
Fix being unable to rename users (#885)
2 parents 2620b05 + aeabf7d commit 192fb87

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

Refresh.Database/GameDatabaseContext.Notifications.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ public void AddNotification(string title, string text, GameUser user, string? ic
1616
{
1717
Title = title,
1818
Text = text,
19-
User = user,
19+
UserId = user.UserId,
2020
FontAwesomeIcon = icon,
2121
CreatedAt = this._time.Now,
2222
};
23-
24-
this.Write(() =>
25-
{
26-
this.GameNotifications.Add(notification);
27-
});
23+
24+
this.GameNotifications.Add(notification);
25+
this.SaveChanges();
2826
}
2927

3028
public void AddErrorNotification(string title, string text, GameUser user)

Refresh.Database/GameDatabaseContext.Users.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,9 @@ public DatabaseList<GameUser> GetAllUsersWithRole(GameUserRole role)
279279
public void RenameUser(GameUser user, string newUsername)
280280
{
281281
string oldUsername = user.Username;
282-
283-
this.Write(() =>
284-
{
285-
user.Username = newUsername;
286-
});
282+
283+
user.Username = newUsername;
284+
this.SaveChanges();
287285

288286
this.AddNotification("Username Updated", $"An admin has updated your account's username from '{oldUsername}' to '{newUsername}'. " +
289287
$"If there are any problems caused by this, please let us know.", user);

Refresh.Database/Models/Notifications/GameNotification.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ public partial class GameNotification
1414
public string Text { get; set; }
1515

1616
public DateTimeOffset CreatedAt { get; set; }
17-
[Required]
17+
[ForeignKey(nameof(UserId)), Required]
1818
public GameUser User { get; set; }
19+
[Required]
20+
public ObjectId UserId { get; set; }
1921

2022
public string FontAwesomeIcon { get; set; }
2123
}

0 commit comments

Comments
 (0)