From 923d117369757898e4339f634f74a067cad23ef2 Mon Sep 17 00:00:00 2001 From: hz Date: Mon, 9 Jun 2025 19:46:06 -0500 Subject: [PATCH] Fixing 500 error for real --- Services/LocationService.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Services/LocationService.cs b/Services/LocationService.cs index d63e2b8..730b996 100644 --- a/Services/LocationService.cs +++ b/Services/LocationService.cs @@ -58,6 +58,9 @@ public class LocationService public virtual async Task AddItemToLocationAsync(string locationId, string itemId) { + if (!ObjectId.TryParse(locationId, out _) || !ObjectId.TryParse(itemId, out _)) + return; + var idFilter = Builders.Filter.Eq(l => l.Id, locationId); // if the Content array is null, initialize it first @@ -71,6 +74,9 @@ public class LocationService public virtual async Task RemoveItemFromLocationAsync(string locationId, string itemId) { + if (!ObjectId.TryParse(locationId, out _) || !ObjectId.TryParse(itemId, out _)) + return; + var filter = Builders.Filter.Eq(l => l.Id, locationId) & Builders.Filter.Ne("Content", BsonNull.Value); var update = Builders.Update.Pull(l => l.Content, itemId); await _locations.UpdateOneAsync(filter, update);