public async Task SendProviderApprenticeshipStopNotification(Apprenticeship apprenticeship, DateTime stopDate) { if (!_configuration.CommitmentNotification.SendEmail) { Logger.Info("Sending email notifications disabled by config."); return; } var emailMessage = new EmailMessage { TemplateId = "ProviderApprenticeshipStopNotification", Tokens = new Dictionary <string, string> { { "EMPLOYER", apprenticeship.LegalEntityName }, { "APPRENTICE", apprenticeship.ApprenticeshipName }, { "DATE", stopDate.ToString("dd/MM/yyyy") }, { "URL", $"{apprenticeship.ProviderId}/apprentices/manage/{HashingService.HashValue(apprenticeship.Id)}/details" } } }; Logger.Info($"Sending email to all provider recipients for Provider {apprenticeship.ProviderId}, template {emailMessage.TemplateId}"); await _providerEmailService.SendEmailToAllProviderRecipients( apprenticeship.ProviderId, string.Empty, emailMessage); }
public void Then_AlphaNumeric_HashId_Should_Not_BeEqual_To_Encoded_Value(string hashId) { //Act var _sut = new HashingService(AllowedCharacters, Hashstring); var encodedValue = _sut.HashValue(hashId); //Assert hashId.Should().NotBe(encodedValue); }
public void Then_AlphaNumeric_HashId_Should_Equal_Decode_Value(string hashId) { //Act var _sut = new HashingService(AllowedCharacters, Hashstring); var encodedValue = _sut.HashValue(hashId); var decodedValue = _sut.DecodeValueToString(encodedValue); //Assert hashId.Should().Be(decodedValue); }
public void Then_Numeric_HashValue_Should_Equal_DecodeValue(long expectTedValue) { // Arrange var _sut = new HashingService(AllowedCharacters, Hashstring); //Act var hash = _sut.HashValue(expectTedValue); var actualValue = _sut.DecodeValue(hash); //Assert expectTedValue.Should().Be(actualValue); }
public void Encode_12345_returns_WDEDP5() { //Arrange const long input = 12345L; var sut = new HashingService(AllowedCharacters, Hashstring); //Act var encodedValue = sut.HashValue(input); //Assert encodedValue.Should().Be("WDEDP5"); }
private CommitmentListItemViewModel MapFrom(CommitmentView listItem, string latestMessage) { return(new CommitmentListItemViewModel { HashedCommitmentId = HashingService.HashValue(listItem.Id), Reference = listItem.Reference, LegalEntityName = listItem.LegalEntityName, ProviderName = listItem.ProviderName, Status = listItem.GetStatus(), EmployerAccountId = listItem.EmployerAccountId, LatestMessage = latestMessage }); }
public void Then_Guid_HashValue_Should_Equal_DecodeValue(string hashValue) { // Arrange var _sut = new HashingService(AllowedCharacters, Hashstring); //Act Guid expectedValue = Guid.Parse(hashValue); var hash = _sut.HashValue(expectedValue); var actualValue = _sut.DecodeValueToGuid(hash); //Assert expectedValue.Should().Be(actualValue); }
private IList <ApprenticeshipListItemViewModel> MapFrom(IEnumerable <Apprenticeship> apprenticeships, GetOverlappingApprenticeshipsQueryResponse overlaps) { var apprenticeViewModels = apprenticeships .Select(x => new ApprenticeshipListItemViewModel { HashedApprenticeshipId = HashingService.HashValue(x.Id), ApprenticeshipName = x.ApprenticeshipName, ApprenticeDateOfBirth = x.DateOfBirth, ULN = x.ULN, CourseCode = x.TrainingCode, CourseName = x.TrainingName, StartDate = x.StartDate, EndDate = x.EndDate, Cost = x.Cost, CanBeApproved = x.CanBeApproved, OverlappingApprenticeships = overlaps?.GetOverlappingApprenticeships(x.Id), OriginalStartDate = x.OriginalStartDate }).ToList(); return(apprenticeViewModels); }
public async Task SendSenderApprovedOrRejectedCommitmentNotification(CommitmentView commitment, Commitments.Api.Types.TransferApprovalStatus newTransferApprovalStatus) { var email = commitment.EmployerLastUpdateInfo?.EmailAddress; if (string.IsNullOrWhiteSpace(email)) { Logger.Info($"No email associated with employer, skipping notification of employer id {commitment.EmployerAccountId} that sender has {newTransferApprovalStatus} cohort id {commitment.Id}"); return; } Logger.Info($"Sending email notification to {email} of employer id {commitment.EmployerAccountId} that sender has {newTransferApprovalStatus} cohort id {commitment.Id}"); var tokens = new Dictionary <string, string> { { "cohort_reference", commitment.Reference }, { "employer_name", commitment.LegalEntityName }, { "sender_name", commitment.TransferSender.Name }, { "employer_hashed_account", HashingService.HashValue(commitment.EmployerAccountId) } }; var notificationCommand = BuildNotificationCommand(email, newTransferApprovalStatus, RecipientType.Employer, tokens); await _mediator.SendAsync(notificationCommand); }
public async Task <string> CreateCohort(int providerId, ConfirmEmployerViewModel confirmEmployerViewModel, string userId, SignInUserModel signinUser) { Logger.Info($"Creating cohort", providerId); var employerAccountId = _publicHashingService.DecodeValue(confirmEmployerViewModel.EmployerAccountPublicHashedId); var relationshipData = await Mediator.Send(new GetProviderRelationshipsWithPermissionQueryRequest { Permission = Operation.CreateCohort, ProviderId = providerId }); //Check that the relationship is a valid selection var relationship = relationshipData.ProviderRelationships.SingleOrDefault(x => x.AccountPublicHashedId == confirmEmployerViewModel.EmployerAccountPublicHashedId && x.AccountLegalEntityPublicHashedId == confirmEmployerViewModel.EmployerAccountLegalEntityPublicHashedId ); if (relationship == null) { throw new InvalidOperationException( $"Error creating cohort - operation not permitted for Provider: {providerId}, Employer Account {employerAccountId}, Legal Entity {confirmEmployerViewModel.EmployerAccountLegalEntityPublicHashedId} "); } var providerResponse = await Mediator.Send(new GetProviderQueryRequest { UKPRN = providerId }); var employerAccountHashedId = HashingService.HashValue(employerAccountId); var accountResponse = await Mediator.Send(new GetEmployerAccountLegalEntitiesRequest { UserId = userId, HashedAccountId = employerAccountHashedId }); var legalEntity = accountResponse.LegalEntities.SingleOrDefault(x => x.AccountLegalEntityPublicHashedId == confirmEmployerViewModel.EmployerAccountLegalEntityPublicHashedId); if (legalEntity == null) { throw new InvalidOperationException( $"Error getting Employer Account Legal entity for {confirmEmployerViewModel.EmployerAccountLegalEntityPublicHashedId}"); } var createCommitmentRequest = new CreateCommitmentCommand { UserId = userId, Commitment = new Commitment { Reference = Guid.NewGuid().ToString().ToUpper(), EmployerAccountId = employerAccountId, LegalEntityId = legalEntity.Code, LegalEntityName = legalEntity.Name, LegalEntityAddress = legalEntity.RegisteredAddress, LegalEntityOrganisationType = (OrganisationType)legalEntity.Source, AccountLegalEntityPublicHashedId = legalEntity.AccountLegalEntityPublicHashedId, ProviderId = providerId, ProviderName = providerResponse.ProvidersView.Provider.ProviderName, CommitmentStatus = CommitmentStatus.New, EditStatus = EditStatus.ProviderOnly, ProviderLastUpdateInfo = new LastUpdateInfo { Name = signinUser.DisplayName, EmailAddress = signinUser.Email } } }; var response = await Mediator.Send(createCommitmentRequest); return(HashingService.HashValue(response.CommitmentId)); }
public async Task <BulkUploadResultViewModel> UploadFile(string userId, UploadApprenticeshipsViewModel uploadApprenticeshipsViewModel, SignInUserModel signInUser) { var commitmentId = HashingService.DecodeValue(uploadApprenticeshipsViewModel.HashedCommitmentId); var providerId = uploadApprenticeshipsViewModel.ProviderId; var fileName = uploadApprenticeshipsViewModel.Attachment?.FileName ?? "<unknown>"; var commitment = await GetCommitment(providerId, commitmentId); AssertCommitmentStatus(commitment); await AssertAutoReservationEnabled(commitment); Logger.Info($"Uploading File - Filename:{fileName}", uploadApprenticeshipsViewModel.ProviderId, commitmentId); var fileValidationResult = await _bulkUploader.ValidateFileStructure(uploadApprenticeshipsViewModel, providerId, commitment); if (fileValidationResult.Errors.Any()) { return(new BulkUploadResultViewModel { BulkUploadId = fileValidationResult.BulkUploadId, HasFileLevelErrors = true, FileLevelErrors = fileValidationResult.Errors }); } Logger.Info("Uploading file of apprentices.", providerId, commitmentId); var rowValidationResult = await _bulkUploader.ValidateFileRows(fileValidationResult.Data, providerId, fileValidationResult.BulkUploadId); var sw = Stopwatch.StartNew(); var overlapErrors = await GetOverlapErrors(fileValidationResult.Data.ToList()); Logger.Trace($"Validating overlaps took {sw.ElapsedMilliseconds}"); var rowErrors = rowValidationResult.Errors.ToList(); rowErrors.AddRange(overlapErrors); var hashedBulkUploadId = HashingService.HashValue(fileValidationResult.BulkUploadId); if (rowErrors.Any()) { Logger.Info($"{rowErrors.Count} Upload errors", providerId, commitmentId); return(new BulkUploadResultViewModel { BulkUploadId = fileValidationResult.BulkUploadId, BulkUploadReference = hashedBulkUploadId, HasRowLevelErrors = true, RowLevelErrors = rowErrors }); } try { await Mediator.Send(new BulkUploadApprenticeshipsCommand { UserId = userId, ProviderId = providerId, CommitmentId = commitmentId, Apprenticeships = await _mapper.MapFrom(commitmentId, rowValidationResult.Data), UserEmailAddress = signInUser.Email, UserDisplayName = signInUser.DisplayName }); } catch (Exception) { var overlaps = (await GetOverlapErrors(fileValidationResult.Data.ToList())).ToList(); if (overlaps.Any()) { return(new BulkUploadResultViewModel { BulkUploadId = fileValidationResult.BulkUploadId, HasRowLevelErrors = true, RowLevelErrors = overlaps }); } throw; } return(new BulkUploadResultViewModel { BulkUploadId = fileValidationResult.BulkUploadId }); }