Example #1
0
        public async Task <ApplicationAcceptedResult> AcceptApplicationAsync(string portalOperationID, Stream xml)
        {
            var operationResult = await IdempotentOperationExecutor.ExecuteAsync(portalOperationID, Common.Models.ServiceOperationTypes.AcceptServiceApplication,
                                                                                 async (oid) =>
            {
                var application = await InitialSaveApplication(xml);

                var action = new ServiceAction()
                {
                    OperationID       = oid,
                    ServiceInstanceID = application.ServiceInstanceID,
                    ApplicationID     = application.ApplicationID.Value,
                    ApplicationStatus = application.Status.Value,
                    ActionTypeID      = ServicеActionTypes.ApplicationAcceptance
                };
                ServiceActionRepository.Create(action);

                var result = new Results.ApplicationAcceptedResult()
                {
                    ApplicationID     = application.ApplicationID.Value,
                    ApplicationNumber = application.ApplicationIdentifier,
                    ApplicationStatus = application.Status,
                    RegistrationTime  = application.RegistrationTime
                };

                return(result);
            },
                                                                                 async (r) =>
            {
                await ActionDispatcher.SendAsync(r);
            });

            return(operationResult);
        }
Example #2
0
        public async Task <ApplicationProcessedResult> ProcessApplicationAsync(long applicationID)
        {
            var result = await IdempotentOperationExecutor.ExecuteAsync(applicationID.ToString(), Common.Models.ServiceOperationTypes.ProcessServiceApplication, (oid) =>
            {
                var application = ApplicationRepository.Search(new ApplicationSearchCriteria()
                {
                    ApplicationIDs = new List <long> {
                        applicationID
                    }
                }).SingleOrDefault();

                if (application == null && application.Status != ApplicationStatuses.Accepted)
                {
                    throw new InvalidOperationException();
                }

                // decide which api to call

                if (application.IsMainApplication)
                {
                    return(RequestApplicationPaymentAsync(oid, application));
                }
                else
                {
                    return(SendCorrectionApplicationToPRAsync(oid, application));
                }
            }, async (operationResult) => {
                // when application is free should be prepared to be sent to PR immediatelly
                if (operationResult.ApplicationStatus == ApplicationStatuses.WaitingRegistration ||
                    operationResult.ApplicationStatus == ApplicationStatuses.InProgress)
                {
                    await ActionDispatcher.SendAsync(operationResult);
                }
            });

            return(result);
        }