private async Task <ProcessDigitalSupportsResponse> HandleInternal(ProcessDigitalSupportsRequest r)
        {
            if (r.FileId == null)
            {
                throw new ArgumentNullException(nameof(r.FileId));
            }
            if (r.RequestingUserId == null)
            {
                throw new ArgumentNullException(nameof(r.RequestingUserId));
            }

            var supports = mapper.Map <IEnumerable <Support> >(r.Supports);

            var processedSupports = ((CreateNewSupportsCommandResult)await supportRepository.Manage(new CreateNewSupportsCommand
            {
                FileId = r.FileId,
                Supports = supports
            })).Supports.ToArray();

            try
            {
                var printRequestId = await printRequestsRepository.Manage(new SavePrintRequest
                {
                    PrintRequest = new ReferralPrintRequest
                    {
                        FileId           = r.FileId,
                        SupportIds       = processedSupports.Select(s => s.Id).ToArray(),
                        IncludeSummary   = r.IncludeSummaryInReferralsPrintout,
                        RequestingUserId = r.RequestingUserId,
                        Type             = ReferralPrintType.New,
                        Comments         = "Process supports"
                    }
                });

                return(new ProcessDigitalSupportsResponse
                {
                    Supports = mapper.Map <IEnumerable <Shared.Contracts.Events.Support> >(processedSupports),
                    PrintRequestId = printRequestId
                });
            }
            catch (Exception)
            {
                await supportRepository.Manage(new ChangeSupportStatusCommand
                {
                    Items = processedSupports.Select(s => SupportStatusTransition.VoidSupport(s.Id, SupportVoidReason.ErrorOnPrintedReferral)).ToArray()
                });

                throw;
            }
        }
Esempio n. 2
0
        public async Task ChangeStatus_Void_Success()
        {
            var support = ((SearchSupportQueryResult)await supportRepository.Query(new SearchSupportsQuery {
                ByEvacuationFileId = TestData.EvacuationFileId
            })).Items
                          .First(s => s.SupportDelivery is Referral && s.Status == SupportStatus.Active);

            var voidedSupportId = ((ChangeSupportStatusCommandResult)await supportRepository.Manage(new ChangeSupportStatusCommand
            {
                Items = new[] { SupportStatusTransition.VoidSupport(support.Id, SupportVoidReason.NewSupplierRequired) }
            })).Ids.ShouldHaveSingleItem();

            voidedSupportId.ShouldBe(support.Id);

            var voidedSupport = ((SearchSupportQueryResult)await supportRepository.Query(new SearchSupportsQuery {
                ById = voidedSupportId
            })).Items.ShouldHaveSingleItem();

            voidedSupport.Status.ShouldBe(SupportStatus.Void);
        }