Exemple #1
0
        public async Task <TResult> Execute(SetContainedViewRequest <TResult> input)
        {
            var ctx = await _contextRepository.CreateSnapshotOfContext(await _contextRepository.Get(input.FlowHandler));

            var newFlowHandler = (await _contextRepository.Get(input.FlowHandler)).NextFlowHandler;

            var flow = await _flows.GetByFlowHandler(newFlowHandler);

            if (flow == null)
            {
                return(await NotFoundResult(input));
            }
            var stepData = await flow.GetCurrentStepData(newFlowHandler,
                                                         stepViewCustomizations : input.ViewCustomizations);

            //update contained step data
            var stepMetaData = stepData.Metadata;

            stepMetaData.ContainedFlowType      = input.NewContainedFlowType;
            stepMetaData.ContainedFlowHandler   = null;
            stepMetaData.ContainedFlowStartType = input.NewContainedFlowStartType;

            await flow.SetCurrentStepData(stepData);

            var result = await input.OnRedirectToCurrent(flow.FlowTypeId, newFlowHandler);

            await _contextRepository.Flush();

            return(result);
        }
        public async Task <TResult> Execute(TriggerEventOnView <TResult> input)
        {
            TResult result;
            var     model = input.Model;


            var flow = await _flows.GetByFlowHandler(model.FlowHandler);

            if (flow == null)
            {
                result = await _resultResolver.Execute(input.ToFlowResolverRequest(new UiFlowStepUnauthorized()));
            }
            else
            {
                var inputErrors = new UiFlowUserInputError[0];
                if (model.DontValidateEvents.All(x => x != input.Event))
                {
                    inputErrors = input.OnExecuteValidation(model).ToArray();
                }

                var actual = await flow.GetCurrentStepData(model.FlowHandler);

                if (actual != null)
                {
                    model = actual.UpdateWithChangesFrom(model, (s, d) => { s.Metadata.DateCreated = actual.Metadata.DateCreated; });
                }

                if (!inputErrors.Any())
                {
                    model = await flow.Execute(input.Event, model, (errors, screenModel) =>
                    {
                        //TODO: prototype implementation --> REVISIT
                        var userInputErrors = errors as UiFlowUserInputError[] ?? errors.ToArray();
                        screenModel.Errors  = userInputErrors;
                        foreach (var error in userInputErrors)
                        {
                            input.OnAddModelError(error.MemberName, error.ErrorMessage);
                        }
                    });
                }
                else
                {
                    model.Errors = inputErrors;
                    await flow.SetCurrentStepData(model);
                }
                result = await _resultResolver.Execute(input.ToFlowResolverRequest(model));

                //TODO: MOVE OUTSIDE BLOCK???
                await _contextRepository.Flush();
            }


            return(result);
        }
        public async Task <TResult> Execute(CurrentViewRequest <TResult> input)
        {
            TResult result;
            var     flow = await _flows.GetByFlowHandler(input.FlowHandler);

            if (flow == null)
            {
                return(await input.BuildResultOnFlowNotFound());
            }
            var stepData = await flow.GetCurrentStepData(input.FlowHandler, input.ViewParameters);

            UiFlowScreenModel actualStepData = null;

            //TODO: is component view property
            if (!input.ResolveAsComponentOnly)
            {
                actualStepData = await InitializeNewContainedFlows(stepData, input.ViewParameters);
            }

            if (actualStepData is ExitReturnToCaller)
            {
                result = await input.OnCallbackCallerFlow(((ExitReturnToCaller)actualStepData));
            }
            else if (actualStepData != null && stepData.FlowHandler != actualStepData.FlowHandler)
            {
                result = await input.BuildResultOnRequestRedirectTo(actualStepData.FlowHandler);
            }
            else
            {
                if (input.OnAddModelError != null)
                {
                    foreach (var error in stepData.Errors)
                    {
                        input.OnAddModelError(error.MemberName, error.ErrorMessage);
                    }
                }

                result = await input.OnBuildView(new CurrentViewRequest <TResult> .BuildViewInput
                {
                    BuildPartial = stepData.Metadata.IsContainedInController() ||
                                   (await _contextRepository.Get(input.FlowHandler)).IsInContainer(),
                    ScreenModel = stepData,
                    ViewName    = flow.CurrentState.ViewName,
                    FlowType    = flow.FlowTypeId
                });
            }
            if (!input.ResolveAsComponentOnly)
            {
                await _contextRepository.Flush();
            }

            return(result);
        }
Exemple #4
0
        public async Task <TResult> Execute(InitialViewRequest <TResult> input)
        {
            if (string.IsNullOrWhiteSpace(input.FlowType))
            {
                throw new ArgumentException("Invalid request: flow type is missing");
            }
            var flow = _flows.GetByFlowType(input.FlowType);

            var viewModel = await flow.StartNew(input.ContainerFlowHandler, input.FlowInput);

            var result = await input.OnBuildView(viewModel);

            await _contextRepository.Flush();

            return(result);
        }