use ChildEntityUpdate also on PUT

This commit is contained in:
Pilzinsel64
2025-04-30 14:16:54 +02:00
parent 1b92549b34
commit 02ef0da374
2 changed files with 13 additions and 1 deletions

View File

@@ -54,6 +54,18 @@ public abstract class BaseChildItemHandler<TEntity, TParent, TUpdateMsg>(IApiSer
return ToClient(entity).ToItemResult(HttpStatusCode.Created); return ToClient(entity).ToItemResult(HttpStatusCode.Created);
} }
public override ApiResult Put(int id, TUpdateMsg msg, ApiRequestInfo req)
{
if (server.Manager.Get<TParent>().FirstOrDefault(n => GetChilds(n).Any(n => n.Id == id)) is not TParent parentEntity)
return ApiResult.NotFound();
if (!server.Manager.Find(id, out TEntity? entity))
return ApiResult.NotFound();
if (UpdateEntity(new ChildEntityUpdate(entity, parentEntity, msg, req)) is ApiResult result)
return result;
server.Manager.Save(entity, true);
return ToClient(entity).ToItemResult();
}
protected virtual TEntity CreateNewEntity(TUpdateMsg msg, TParent parent) protected virtual TEntity CreateNewEntity(TUpdateMsg msg, TParent parent)
{ {
return CreateNewEntity(msg); return CreateNewEntity(msg);

View File

@@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<Version>2.5.2</Version> <Version>2.5.3</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>