Ejemplo n.º 1
0
        public async Task <string> Handle(ProcessSupportsCommand cmd)
        {
            if (string.IsNullOrEmpty(cmd.FileId))
            {
                throw new ArgumentNullException(nameof(cmd.FileId));
            }
            if (string.IsNullOrEmpty(cmd.RequestingUserId))
            {
                throw new ArgumentNullException(nameof(cmd.RequestingUserId));
            }

            //verify no paper supports included
            var paperReferrals = cmd.Supports.Where(s => s is Referral r && r.IsPaperReferral).Cast <Referral>().Select(r => r.ExternalReferenceId).ToArray();

            if (paperReferrals.Any())
            {
                throw new BusinessValidationException($"file {cmd.FileId} error: cannot process paper referrals {string.Join(',', paperReferrals)} as digital");
            }

            var requestingUser = (await teamRepository.GetMembers(userId: cmd.RequestingUserId, includeStatuses: activeOnlyStatus)).Cast <Resources.Teams.TeamMember>().Single();

            foreach (var support in cmd.Supports)
            {
                support.CreatedBy = new Shared.Contracts.Events.TeamMember {
                    Id = requestingUser.Id
                };
                support.CreatedOn = DateTime.UtcNow;
            }

            //Not ideal solution - the IDs are concatenated by CaseRepository to ensure
            //all supports are created in a single transaction
            var supportIds = (await caseRepository.ManageCase(new SaveEvacuationFileSupportCommand
            {
                FileId = cmd.FileId,
                Supports = mapper.Map <IEnumerable <Resources.Cases.Evacuations.Support> >(cmd.Supports)
            })).Id.Split(';');

            var printRequestId = await printingRepository.Manage(new SavePrintRequest
            {
                PrintRequest = new ReferralPrintRequest
                {
                    FileId           = cmd.FileId,
                    SupportIds       = supportIds,
                    IncludeSummary   = cmd.IncludeSummaryInReferralsPrintout,
                    RequestingUserId = requestingUser.Id,
                    Type             = ReferralPrintType.New,
                    Comments         = "Process supports"
                }
            });

            return(printRequestId);
        }
        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;
            }
        }
Ejemplo n.º 3
0
        public async Task <string> Handle(ProcessSupportsCommand cmd)
        {
            if (string.IsNullOrEmpty(cmd.FileId))
            {
                throw new ArgumentNullException(nameof(cmd.FileId));
            }
            if (string.IsNullOrEmpty(cmd.RequestingUserId))
            {
                throw new ArgumentNullException(nameof(cmd.RequestingUserId));
            }

            var requestingUser = (await teamRepository.GetMembers(userId: cmd.RequestingUserId)).Cast <Resources.Team.TeamMember>().Single();

            //Not ideal solution - the IDs are concatenated by CaseRepository to ensure
            //all supports are created in a single transaction
            var supportIds = (await caseRepository.ManageCase(new SaveEvacuationFileSupportCommand
            {
                FileId = cmd.FileId,
                Supports = mapper.Map <IEnumerable <Resources.Cases.Support> >(cmd.supports)
            })).Id.Split(';');

            var referralPrintId = await printingRepository.Manage(new SavePrintRequest
            {
                PrintRequest = new ReferralPrintRequest
                {
                    FileId           = cmd.FileId,
                    SupportIds       = supportIds,
                    IncludeSummary   = cmd.IncludeSummaryInReferralsPrintout,
                    RequestingUserId = requestingUser.Id,
                    Type             = ReferralPrintType.New,
                    Comments         = "Process supports"
                }
            });

            return(referralPrintId);
        }