Example #1
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractPayload        = request.Payload as IContractProcessingPayload;
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = currentProcessingState;

            if (!newProcessingState.ContractState.IsPendingApproval.GetValueOrDefault())
            {
                var contractTracking = new ContractTrackingReference(contractPayload.TrackingReference);

                if (_persistence.CreateContractTrackingReference(contractTracking).IsSaved)
                {
                    //update the external state
                    newProcessingState = currentProcessingState.Clone(s => s.SetIsPendingApproval(true));
                }
            }

            if (newProcessingState.ContractState.IsPendingApproval.GetValueOrDefault())
            {
                //update the public state
                newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsPendingApproval()
                                                              .And()
                                                              .SetContractStatus(ContractStatus.InFlight));
            }

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
        private ContractTrackingReference CreateContractTrackingReference(long contractId, Guid itemReference,
                                                                          ContractTrackingState state   = ContractTrackingState.ActionsPending,
                                                                          ContractStatus contractStatus = ContractStatus.AvailableForApproval)
        {
            var contract = FluentContract
                           .Create()
                           .ApplyDefaults()
                           .ContractStatus(contractStatus)
                           .Save(this);

            var trackingReference = new ContractTrackingReference()
            {
                ContractId = contract.Id, ItemReference = itemReference.ToString(), State = state
            };

            var roleIds           = Enumerable.Empty <long>();
            var changeSet         = base.contractTrackingReferenceRecordType.GetNewChangeSet() as ChangeSet <long, ContractTrackingReference>;
            var changeSetSettings = new ProcessChangeSetSettings(username: MrAdmin.Name);
            var itemRef           = 1L;

            changeSet.AddCreate(itemRef, trackingReference, roleIds, roleIds);

            var processResult = contractTrackingReferenceRecordType.ProcessChangeSet(PreliminaryContractDataService, changeSet, changeSetSettings);

            return(processResult.SuccessfullyCreatedItems[processResult.SuccessfullyCreated[itemRef]] as ContractTrackingReference);
        }
        public (bool IsSaved, string[] Errors) CreateContractTrackingReference(ContractTrackingReference contractTracking)
        {
            var contractReference = contractTracking.TrackingReference;

            if (!_contractStore.ContainsKey(contractReference))
            {
                _contractStore.Add(contractReference, contractTracking);
            }

            return(true, new string[0]);
        }
        private List <ActionTrackingReference> CreateActionTrackingReferences(ContractTrackingReference contract,
                                                                              ActionTrackingState state = ActionTrackingState.Pending)
        {
            var roleIds           = Enumerable.Empty <long>();
            var changeSet         = base.actionTrackingReferenceRecordType.GetNewChangeSet() as ChangeSet <long, ActionTrackingReference>;
            var changeSetSettings = new ProcessChangeSetSettings(username: MrAdmin.Name);

            for (var itemRef = 1L; itemRef <= 3; itemRef++)
            {
                var action = new ActionTrackingReference()
                {
                    ItemReference = contract.ItemReference, ActionKey = ActionKeyHelpers.BuildKey(contract.ItemReference, itemRef, itemRef * 10), ActionReference = Guid.NewGuid().ToString(), State = state
                };
                changeSet.AddCreate(itemRef, action, roleIds, roleIds);
            }

            var processResult = actionTrackingReferenceRecordType.ProcessChangeSet(PreliminaryContractDataService, changeSet, changeSetSettings);

            return(processResult
                   .SuccessfullyCreatedItems
                   .Values
                   .Select(i => i as ActionTrackingReference)
                   .ToList());
        }