Exemple #1
0
        public async Task <Unit> Handle(CourseStoppedCommand request, CancellationToken cancellationToken)
        {
            var courseDemand =
                await _employerDemandApiClient.Get <GetEmployerDemandResponse>(
                    new GetEmployerDemandRequest(request.EmployerDemandId));

            var emailModel = new StopSharingEmployerDemandCourseClosedEmail(
                courseDemand.ContactEmailAddress,
                courseDemand.OrganisationName,
                courseDemand.Course.Title,
                courseDemand.Course.Level,
                courseDemand.Location.Name,
                courseDemand.NumberOfApprentices);

            await _notificationService.Send(new SendEmailCommand(emailModel.TemplateId, emailModel.RecipientAddress, emailModel.Tokens));

            var auditTask = _employerDemandApiClient.PostWithResponseCode <object>(
                new PostEmployerDemandNotificationAuditRequest(request.Id, request.EmployerDemandId, NotificationType.StoppedCourseClosed));
            var patchTask = _employerDemandApiClient.PatchWithResponseCode(new PatchCourseDemandRequest(
                                                                               request.EmployerDemandId, new PatchOperation
            {
                Path  = "Stopped",
                Value = true
            }));

            await Task.WhenAll(auditTask, patchTask);

            return(Unit.Value);
        }
        public async Task <VerifyEmployerDemandCommandResult> Handle(VerifyEmployerDemandCommand request, CancellationToken cancellationToken)
        {
            var getEmployerDemandResponse =
                await _apiClient.Get <GetEmployerDemandResponse>(new GetEmployerDemandRequest(request.Id));

            if (getEmployerDemandResponse == null)
            {
                return(new VerifyEmployerDemandCommandResult
                {
                    EmployerDemand = null
                });
            }

            if (getEmployerDemandResponse.EmailVerified ||
                getEmployerDemandResponse.ContactEmailAddress == string.Empty)
            {
                return(new VerifyEmployerDemandCommandResult
                {
                    EmployerDemand = getEmployerDemandResponse
                });
            }

            var verifyEmailResponse = await _apiClient.PatchWithResponseCode(new PatchCourseDemandRequest(
                                                                                 request.Id, new PatchOperation
            {
                Path = "EmailVerified",
                Value = true
            }));

            if (verifyEmailResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpRequestContentException($"Response status code does not indicate success: {(int)verifyEmailResponse.StatusCode} ({verifyEmailResponse.StatusCode})", verifyEmailResponse.StatusCode, verifyEmailResponse.ErrorContent);
            }

            if (verifyEmailResponse.StatusCode == HttpStatusCode.OK)
            {
                var emailModel = new CreateDemandConfirmationEmail(
                    getEmployerDemandResponse.ContactEmailAddress,
                    getEmployerDemandResponse.OrganisationName,
                    getEmployerDemandResponse.Course.Title,
                    getEmployerDemandResponse.Course.Level,
                    getEmployerDemandResponse.Location.Name,
                    getEmployerDemandResponse.NumberOfApprentices,
                    getEmployerDemandResponse.StopSharingUrl
                    );
                await _notificationService.Send(new SendEmailCommand(emailModel.TemplateId, emailModel.RecipientAddress, emailModel.Tokens));

                getEmployerDemandResponse.EmailVerified = true;
            }

            return(new VerifyEmployerDemandCommandResult
            {
                EmployerDemand = getEmployerDemandResponse
            });
        }
Exemple #3
0
        public async Task <StopEmployerDemandCommandResult> Handle(StopEmployerDemandCommand request, CancellationToken cancellationToken)
        {
            var getEmployerDemandResponse = await _demandApiClient.Get <GetEmployerDemandResponse>(
                new GetEmployerDemandRequest(request.EmployerDemandId));

            if (getEmployerDemandResponse == null)
            {
                return(new StopEmployerDemandCommandResult());
            }

            if (getEmployerDemandResponse.Stopped)
            {
                return(new StopEmployerDemandCommandResult
                {
                    EmployerDemand = getEmployerDemandResponse
                });
            }

            var stopDemandResponse = await _demandApiClient.PatchWithResponseCode(
                new PatchCourseDemandRequest(request.EmployerDemandId, new PatchOperation
            {
                Path = "Stopped",
                Value = true
            }));

            if (stopDemandResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpRequestContentException($"Response status code does not indicate success: {(int)stopDemandResponse.StatusCode} ({stopDemandResponse.StatusCode})", stopDemandResponse.StatusCode, stopDemandResponse.ErrorContent);
            }

            await _demandApiClient.PostWithResponseCode <object>(
                new PostEmployerDemandNotificationAuditRequest(request.Id, request.EmployerDemandId, NotificationType.StoppedByUser));

            var stopDemandResponseBody =
                JsonConvert.DeserializeObject <GetEmployerDemandResponse>(stopDemandResponse.Body);

            var emailArgs = new StopSharingEmployerDemandEmail(
                stopDemandResponseBody.ContactEmailAddress,
                stopDemandResponseBody.OrganisationName,
                stopDemandResponseBody.Course.Title,
                stopDemandResponseBody.Course.Level,
                stopDemandResponseBody.Location.Name,
                stopDemandResponseBody.NumberOfApprentices,
                stopDemandResponseBody.StartSharingUrl);
            await _notificationService.Send(new SendEmailCommand(
                                                EmailConstants.StopSharingEmployerDemandTemplateId,
                                                stopDemandResponseBody.ContactEmailAddress,
                                                emailArgs.Tokens));

            return(new StopEmployerDemandCommandResult
            {
                EmployerDemand = stopDemandResponseBody
            });
        }
Exemple #4
0
        public async Task <Unit> Handle(AnonymiseDemandCommand request, CancellationToken cancellationToken)
        {
            await _employerDemandApiClient.PatchWithResponseCode(
                new PatchCourseDemandRequest(
                    request.EmployerDemandId,
                    new PatchOperation
            {
                Path = "ContactEmailAddress",
                Value = string.Empty
            }));

            return(Unit.Value);
        }