public MediatorResponse <ShareApplicationsViewModel> ShareApplications(ShareApplicationsViewModel viewModel, UrlHelper urlHelper) { var validationResult = _shareApplicationsViewModelValidator.Validate(viewModel); var newViewModel = _applicationProvider.GetShareApplicationsViewModel(viewModel.VacancyReferenceNumber); newViewModel.SelectedApplicationIds = viewModel.SelectedApplicationIds; if (!validationResult.IsValid) { return(GetMediatorResponse(ApplicationMediatorCodes.ShareApplications.FailedValidation, newViewModel, validationResult)); } var applicationLinks = new Dictionary <string, string>(); foreach (var selectedApplicationId in viewModel.SelectedApplicationIds) { var application = newViewModel.ApplicationSummaries.Single(a => a.ApplicationId == selectedApplicationId); var anonymisedApplicationLinkData = new AnonymisedApplicationLink(application.ApplicationId, _dateTimeService.TwoWeeksFromUtcNow); var encryptedLinkData = _encryptionService.Encrypt(anonymisedApplicationLinkData); var urlEncodedLinkData = HttpUtility.UrlEncode(encryptedLinkData); var routeName = newViewModel.VacancyType == VacancyType.Apprenticeship ? RecruitmentRouteNames.ViewAnonymousApprenticeshipApplication : RecruitmentRouteNames.ViewAnonymousTraineeshipApplication; var routeValues = new RouteValueDictionary(); routeValues["application"] = urlEncodedLinkData; var link = urlHelper.RouteUrl(routeName, routeValues); applicationLinks[application.ApplicantID] = link; } _applicationProvider.ShareApplications(viewModel.VacancyReferenceNumber, newViewModel.ProviderName, applicationLinks, _dateTimeService.TwoWeeksFromUtcNow, viewModel.RecipientEmailAddress); return(GetMediatorResponse(ApplicationMediatorCodes.ShareApplications.Ok, newViewModel)); }