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 TParent : class, IDataObject
|
||||||
where TUpdateMsg : ApiMessage
|
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 RegisterGetAll => true;
|
||||||
protected virtual bool RegisterPost => 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))
|
if (!server.Manager.Find(parent, out TParent? parentEntity))
|
||||||
return ApiResult.NotFound();
|
return ApiResult.NotFound();
|
||||||
var entity = CreateNewEntity(msg);
|
var entity = CreateNewEntity(msg, parentEntity);
|
||||||
if (UpdateEntity(new(entity, msg, req)) is ApiResult result)
|
if (UpdateEntity(new ChildEntityUpdate(entity, parentEntity, msg, req)) is ApiResult result)
|
||||||
return result;
|
return result;
|
||||||
GetChilds(parentEntity).Add(entity);
|
GetChilds(parentEntity).Add(entity);
|
||||||
server.Manager.Save(parentEntity, true);
|
server.Manager.Save(parentEntity, true);
|
||||||
return ToClient(entity).ToItemResult(HttpStatusCode.Created);
|
return ToClient(entity).ToItemResult(HttpStatusCode.Created);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual TEntity CreateNewEntity(TUpdateMsg msg, TParent parent)
|
||||||
|
{
|
||||||
|
return CreateNewEntity(msg);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract IList<TEntity> GetChilds(TParent parent);
|
public abstract IList<TEntity> GetChilds(TParent parent);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user