diff options
author | crupest <crupest@outlook.com> | 2022-12-17 19:07:23 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:53 +0800 |
commit | 7407875fb75bcd90f6f7ef54573483fe2f3cfb84 (patch) | |
tree | ed55de998706e6805f71614d20d2602d1b3b599f /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs | |
parent | 4595650f6e36ff413bcb65f5419daf8f9bfee9de (diff) | |
download | crupest-7407875fb75bcd90f6f7ef54573483fe2f3cfb84.tar.gz crupest-7407875fb75bcd90f6f7ef54573483fe2f3cfb84.tar.bz2 crupest-7407875fb75bcd90f6f7ef54573483fe2f3cfb84.zip |
Develop secret api. v41
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs index e893638..1265fe9 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs @@ -93,36 +93,20 @@ public class EntityJsonHelper<TEntity> where TEntity : class return ConvertJsonElementToInsertClauses(document.RootElement); } - public IUpdateClause ConvertJsonElementToUpdateClause(JsonDocument json) + public IUpdateClause ConvertJsonElementToUpdateClause(JsonElement rootElement, bool saveNull) { var updateClause = UpdateClause.Create(); - if (json.RootElement.ValueKind != JsonValueKind.Object) + if (rootElement.ValueKind != JsonValueKind.Object) { throw new UserException("The root element must be an object."); } - bool saveNull = false; - - if (json.RootElement.TryGetProperty("$saveNull", out var propertyElement)) - { - if (propertyElement.ValueKind is not JsonValueKind.True or JsonValueKind.False) - { - throw new UserException("$saveNull can only be true or false."); - } - - if (propertyElement.ValueKind is JsonValueKind.True) - { - saveNull = true; - } - } - - foreach (var column in _table.PropertyColumns) { object? value = null; - if (json.RootElement.TryGetProperty(column.ColumnName, out propertyElement)) + if (rootElement.TryGetProperty(column.ColumnName, out var propertyElement)) { value = propertyElement.ValueKind switch { @@ -151,9 +135,36 @@ public class EntityJsonHelper<TEntity> where TEntity : class return updateClause; } + public IUpdateClause ConvertJsonElementToUpdateClause(JsonElement rootElement) + { + var updateClause = UpdateClause.Create(); + + if (rootElement.ValueKind != JsonValueKind.Object) + { + throw new UserException("The root element must be an object."); + } + + bool saveNull = false; + + if (rootElement.TryGetProperty("$saveNull", out var propertyElement)) + { + if (propertyElement.ValueKind is not JsonValueKind.True or JsonValueKind.False) + { + throw new UserException("$saveNull can only be true or false."); + } + + if (propertyElement.ValueKind is JsonValueKind.True) + { + saveNull = true; + } + } + + return ConvertJsonElementToUpdateClause(rootElement, saveNull); + } + public IUpdateClause ConvertJsonToUpdateClause(string json) { var document = JsonSerializer.Deserialize<JsonDocument>(json, _jsonSerializerOptions.CurrentValue)!; - return ConvertJsonElementToUpdateClause(document); + return ConvertJsonElementToUpdateClause(document.RootElement); } } |