public IActionResult CreateAccessToken([FromBody, SwaggerRequestBody("Candidate access token request (must match an existing candidate).", Required = true)] ExistingCandidateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            if (_appSettings.IsCrmIntegrationPaused)
            {
                return(NotFound());
            }

            var candidate = _crm.MatchCandidate(request);

            if (candidate == null)
            {
                return(NotFound());
            }

            var token           = _accessTokenService.GenerateToken(request, (Guid)candidate.Id);
            var personalisation = new Dictionary <string, dynamic> {
                { "pin_code", token }
            };

            // We respond immediately/assume this will be successful.
            _notifyService.SendEmailAsync(request.Email, NotifyService.NewPinCodeEmailTemplateId, personalisation);

            return(NoContent());
        }
Пример #2
0
        public void Run(string json, PerformContext context)
        {
            _logger.LogInformation($"UpsertCandidateJob - Started ({AttemptInfo(context, _contextAdapter)})");
            _logger.LogInformation($"UpsertCandidateJob - Payload {Redactor.RedactJson(json)}");

            var candidate = json.DeserializeChangeTracked <Candidate>();

            if (IsLastAttempt(context, _contextAdapter))
            {
                var personalisation = new Dictionary <string, dynamic>();

                // We fire and forget the email, ensuring the job succeeds.
                _notifyService.SendEmailAsync(
                    candidate.Email,
                    NotifyService.CandidateRegistrationFailedEmailTemplateId,
                    personalisation);
                _logger.LogInformation("UpsertCandidateJob - Deleted");
            }
            else
            {
                var registrations = ClearTeachingEventRegistrations(candidate);
                var phoneCall     = ClearPhoneCall(candidate);
                SaveCandidate(candidate);
                SaveTeachingEventRegistrations(registrations, candidate);
                SavePhoneCall(phoneCall, candidate);
                IncrementCallbackBookingQuotaNumberOfBookings(phoneCall);

                _logger.LogInformation($"UpsertCandidateJob - Succeeded - {candidate.Id}");
            }

            var duration = (DateTime.UtcNow - _contextAdapter.GetJobCreatedAt(context)).TotalSeconds;

            _metrics.HangfireJobQueueDuration.WithLabels(new[] { "UpsertCandidateJob" }).Observe(duration);
        }