ChildUpdateEntity object on POST
This commit is contained in:
@@ -12,6 +12,11 @@ public abstract class BaseChildItemHandler<TEntity, TParent, TUpdateMsg>(IApiSer
|
||||
where TParent : class, IDataObject
|
||||
where TUpdateMsg : ApiMessage
|
||||
{
|
||||
public class ChildEntityUpdate(TEntity entity, TParent parent, TUpdateMsg updateMsg, ApiRequestInfo reqest) : EntityUpdate(entity, updateMsg, reqest)
|
||||
{
|
||||
public TParent Parent { get; } = parent;
|
||||
}
|
||||
|
||||
protected virtual bool RegisterGetAll => true;
|
||||
protected virtual bool RegisterPost => true;
|
||||
|
||||
@@ -41,13 +46,18 @@ public abstract class BaseChildItemHandler<TEntity, TParent, TUpdateMsg>(IApiSer
|
||||
{
|
||||
if (!server.Manager.Find(parent, out TParent? parentEntity))
|
||||
return ApiResult.NotFound();
|
||||
var entity = CreateNewEntity(msg);
|
||||
if (UpdateEntity(new(entity, msg, req)) is ApiResult result)
|
||||
var entity = CreateNewEntity(msg, parentEntity);
|
||||
if (UpdateEntity(new ChildEntityUpdate(entity, parentEntity, msg, req)) is ApiResult result)
|
||||
return result;
|
||||
GetChilds(parentEntity).Add(entity);
|
||||
server.Manager.Save(parentEntity, true);
|
||||
return ToClient(entity).ToItemResult(HttpStatusCode.Created);
|
||||
}
|
||||
|
||||
protected virtual TEntity CreateNewEntity(TUpdateMsg msg, TParent parent)
|
||||
{
|
||||
return CreateNewEntity(msg);
|
||||
}
|
||||
|
||||
public abstract IList<TEntity> GetChilds(TParent parent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user