private async Task Delete(CRUDContext <TService> ctx, RunTimeMetadata metadata, ChangeSetRequest changeSet, RowInfo rowInfo) { TService service = ctx.Service; IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper(); CheckRowInfo(rowInfo); using (RequestCallContext callContext = new RequestCallContext(CRUDContext <TService> .CreateRequestContext(service, changeSet, rowInfo))) { rowInfo.SetChangeState(new EntityChangeState()); await serviceHelper.DeleteEntity(metadata, rowInfo);; } }
private async Task Insert(CRUDContext <TService> ctx, RunTimeMetadata metadata, ChangeSetRequest changeSet, IChangeSetGraph graph, RowInfo rowInfo) { TService service = ctx.Service; IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper(); CheckRowInfo(rowInfo); using (RequestCallContext callContext = new RequestCallContext(CRUDContext <TService> .CreateRequestContext(service, changeSet, rowInfo))) { rowInfo.SetChangeState(new EntityChangeState { ParentRows = graph.GetParents(rowInfo) }); await serviceHelper.InsertEntity(metadata, rowInfo); } }
private async Task <bool> ValidateRows(CRUDContext <TService> ctx, ChangeSetRequest changeSet, RunTimeMetadata metadata, IEnumerable <RowInfo> rows) { TService service = ctx.Service; IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper(); foreach (RowInfo rowInfo in rows) { RequestContext req = CRUDContext <TService> .CreateRequestContext(service, changeSet, rowInfo); using (RequestCallContext callContext = new RequestCallContext(req)) { if (!await serviceHelper.ValidateEntity(metadata, req)) { rowInfo.invalid = rowInfo.GetChangeState().ValidationErrors; return(false); } } } return(true); }
public async Task Invoke(CRUDContext <TService> ctx) { IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper(); IDataHelper <TService> dataHelper = ctx.ServiceContainer.GetDataHelper(); Metadata.RunTimeMetadata metadata = ctx.Service.GetMetadata(); ChangeSetRequest changeSet = ctx.Request; IChangeSetGraph graph = ctx.Properties.Get <IChangeSetGraph>(CRUDContext <TService> .CHANGE_GRAPH_KEY) ?? throw new InvalidOperationException("Could not get Graph changes from properties"); CRUDServiceMethods serviceMethods = ctx.Properties.Get <CRUDServiceMethods>(CRUDContext <TService> .CHANGE_METHODS_KEY) ?? throw new InvalidOperationException("Could not get CRUD Service methods from properties"); RequestContext req = CRUDContext <TService> .CreateRequestContext(ctx.Service, changeSet); using (RequestCallContext callContext = new RequestCallContext(req)) { await serviceMethods.ExecuteChangeSet(); await serviceHelper.AfterExecuteChangeSet(changeSet); await serviceMethods.AfterChangeSetExecuted(); foreach (RowInfo rowInfo in graph.AllList) { if (rowInfo.changeType != ChangeType.Deleted) { serviceHelper.UpdateRowInfoAfterUpdates(rowInfo); } } SubResultList subResults = new SubResultList(); await serviceHelper.AfterChangeSetCommited(changeSet, subResults); await serviceMethods.AfterChangeSetCommited(subResults); SubsetsGenerator subsetsGenerator = new SubsetsGenerator(metadata, dataHelper); ctx.Response.subsets = subsetsGenerator.CreateSubsets(subResults); } await _next(ctx); }