コード例 #1
0
        public async Task <string> Handle(SubmitEvacuationFileCommand cmd)
        {
            var file    = mapper.Map <Resources.Cases.EvacuationFile>(cmd.File);
            var contact = (await contactRepository.QueryContact(new ContactQuery {
                ContactId = file.PrimaryRegistrantId
            })).Items.SingleOrDefault();

            if (contact == null)
            {
                throw new Exception($"Registrant not found '{file.PrimaryRegistrantId}'");
            }

            var caseId = (await caseRepository.ManageCase(new SaveEvacuationFile {
                EvacuationFile = file
            })).CaseId;

            if (cmd.File.SecurityPhraseChanged)
            {
                await caseRepository.ManageCase(new UpdateSecurityPhrase { Id = caseId, SecurityPhrase = file.SecurityPhrase });
            }

            if (string.IsNullOrEmpty(file.Id) && !string.IsNullOrEmpty(contact.Email))
            {
                //notify registrant of the new file and has email
                await SendEmailNotification(
                    SubmissionTemplateType.NewEvacuationFileSubmission,
                    email : contact.Email,
                    name : $"{contact.LastName}, {contact.FirstName}",
                    tokens : new[] { KeyValuePair.Create("fileNumber", caseId) });
            }

            return(caseId);
        }
コード例 #2
0
        public async Task <string> Handle(SubmitEvacuationFileCommand cmd)
        {
            var file = mapper.Map <Resources.Cases.Evacuations.EvacuationFile>(cmd.File);

            var query = new RegistrantQuery();

            //TODO: replace this with an explicit property for userid
            if (Guid.TryParse(file.PrimaryRegistrantId, out var _))
            {
                query.ContactId = file.PrimaryRegistrantId;
            }
            else
            {
                query.UserId = file.PrimaryRegistrantId;
            }

            var contact = (await contactRepository.QueryContact(query)).Items.SingleOrDefault();

            if (contact == null)
            {
                throw new NotFoundException($"Registrant not found '{file.PrimaryRegistrantId}'", file.PrimaryRegistrantId);
            }
            file.PrimaryRegistrantId = contact.Id;

            if (!string.IsNullOrEmpty(file.Id))
            {
                var caseRecord   = (await caseRepository.QueryCase(new Resources.Cases.EvacuationFilesQuery {
                    FileId = file.Id
                })).Items.SingleOrDefault();
                var existingFile = mapper.Map <Resources.Cases.Evacuations.EvacuationFile>(caseRecord);

                if (!string.IsNullOrEmpty(existingFile.TaskId) && !existingFile.TaskId.Equals(file.TaskId, StringComparison.Ordinal))
                {
                    throw new BusinessLogicException($"The ESS Task Number cannot be modified or updated once it's been initially assigned.");
                }
            }

            var caseId = (await caseRepository.ManageCase(new SubmitEvacuationFileNeedsAssessment {
                EvacuationFile = file
            })).Id;

            if (string.IsNullOrEmpty(file.Id) && !string.IsNullOrEmpty(contact.Email))
            {
                //notify registrant of the new file and has email
                await SendEmailNotification(
                    SubmissionTemplateType.NewEvacuationFileSubmission,
                    email : contact.Email,
                    name : $"{contact.LastName}, {contact.FirstName}",
                    tokens : new[] { KeyValuePair.Create("fileNumber", caseId) });
            }

            return(caseId);
        }
コード例 #3
0
        public async Task CanSubmitNewEvacuation()
        {
            var registrant            = (await GetRegistrantByUserId("CHRIS-TEST")).RegistrantProfile;
            var textContextIdentifier = DateTime.Now.ToShortTimeString();
            var needsAssessment       = new NeedsAssessment
            {
                HouseholdMembers = new[]
                {
                    new HouseholdMember
                    {
                        Id = null,

                        FirstName   = $"MemRegTestFirst-{textContextIdentifier}",
                        LastName    = $"MemRegTestLast-{textContextIdentifier}",
                        Gender      = "X",
                        DateOfBirth = "2010-01-01"
                    }
                },
                HaveMedication                  = false,
                Insurance                       = InsuranceOption.Yes,
                HaveSpecialDiet                 = true,
                SpecialDietDetails              = "Gluten Free",
                HasPetsFood                     = true,
                CanEvacueeProvideClothing       = false,
                CanEvacueeProvideFood           = true,
                CanEvacueeProvideIncidentals    = null,
                CanEvacueeProvideLodging        = false,
                CanEvacueeProvideTransportation = true,
                Pets = new[]
                {
                    new Pet {
                        Type = $"dog{textContextIdentifier}", Quantity = "4"
                    }
                }
            };
            var cmd = new SubmitEvacuationFileCommand
            {
                File = new EvacuationFile
                {
                    Id = null,
                    EvacuatedFromAddress = new Address
                    {
                        AddressLine1  = $"addr1-{textContextIdentifier}",
                        Country       = "CAN",
                        Community     = "226adfaf-9f97-ea11-b813-005056830319",
                        StateProvince = "BC",
                        PostalCode    = "v1v 1v1"
                    },
                    EvacuationDate      = DateTime.Now,
                    NeedsAssessments    = new[] { needsAssessment },
                    PrimaryRegistrantId = registrant.Id
                },
            };

            var fileId = await manager.Handle(cmd);

            fileId.ShouldNotBeNull();

            var file = (await GetRegistrantFilesByPrimaryRegistrantId(registrant.Id)).Where(f => f.Id == fileId).ShouldHaveSingleItem();

            file.PrimaryRegistrantId.ShouldBe(registrant.Id);
        }