Example #1
0
        public async Task <ActionResult <EnrolmentCertificateAccessToken> > SendProvisionerLink(int careSettingCode, FromBodyText providedEmails)
        {
            if (string.IsNullOrWhiteSpace(providedEmails))
            {
                this.ModelState.AddModelError("Email(s)", "No emails were provided.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            string[] emails = ((string)providedEmails).Split(",");

            // Emails are either "Other" provisioners, or office manager(s)
            if (emails.Any() && !EmailService.AreValidEmails(emails))
            {
                this.ModelState.AddModelError("Email(s)", "The email(s) provided are not valid.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

            if (enrollee == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "No enrollee exists for this User Id.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (enrollee.ExpiryDate == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in a finished state.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (!enrollee.CurrentStatus.IsType(StatusType.Editable))
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in an editable state.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            var createdToken = await _certificateService.CreateCertificateAccessTokenAsync(enrollee.Id);

            await _emailService.SendProvisionerLinkAsync(emails, createdToken, careSettingCode);

            await _businessEventService.CreateEmailEventAsync(enrollee.Id, "Provisioner link sent to email(s): " + string.Join(",", emails));

            return(CreatedAtAction(
                       nameof(GetEnrolmentCertificate),
                       new { accessTokenId = createdToken.Id },
                       ApiResponse.Result(createdToken)
                       ));
        }
        public async Task <ActionResult <EnrolmentCertificateAccessToken> > CreateEnrolmentCertificateAccessToken()
        {
            var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

            if (enrollee == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "No enrollee exists for this User Id.");
                return(BadRequest(new ApiBadRequestResponse(this.ModelState)));
            }
            if (enrollee.CurrentStatus?.Status.Code != Status.ACCEPTED_TOS_CODE)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in a finished state.");
                return(BadRequest(new ApiBadRequestResponse(this.ModelState)));
            }

            var createdToken = await _certificateService.CreateCertificateAccessTokenAsync(enrollee);

            return(CreatedAtAction(nameof(GetEnrolmentCertificate), new { accessTokenId = createdToken.Id }, new ApiCreatedResponse <EnrolmentCertificateAccessToken>(createdToken)));
        }
        public async Task <ActionResult <EnrolmentCertificateAccessToken> > SendProvisionerLink(int careSettingCode, FromBodyText providedEmails)
        {
            var emails = Email.ParseCommaSeparatedEmails(providedEmails);

            if (!emails.Any())
            {
                ModelState.AddModelError("Emails", "The email(s) provided are not valid.");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }

            var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

            if (enrollee == null)
            {
                ModelState.AddModelError("Enrollee.UserId", "No enrollee exists for this User Id.");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }
            if (enrollee.ExpiryDate == null)
            {
                ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in a finished state.");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }
            if (!enrollee.CurrentStatus.IsType(StatusType.Editable))
            {
                ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in an editable state.");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }
            var createdToken = await _certificateService.CreateCertificateAccessTokenAsync(enrollee.Id);

            await _emailService.SendProvisionerLinkAsync(emails, createdToken, careSettingCode);

            await _businessEventService.CreateEmailEventAsync(enrollee.Id, $"Provisioner link sent to email(s): {providedEmails}");

            return(CreatedAtAction(
                       nameof(GetEnrolmentCertificate),
                       new { accessTokenId = createdToken.Id },
                       ApiResponse.Result(createdToken)
                       ));
        }
Example #4
0
        public async Task <ActionResult <EnrolmentCertificateAccessToken> > SendProvisionerLink(string provisionerName, FromBodyText providedEmails)
        {
            // TODO temporary removed and may be removed permanently
            // var provisionerNames = _certificateService.GetPharmaNetProvisionerNames();
            // if (!provisionerNames.Contains(provisionerName) && provisionerName != "Other")
            if (provisionerName != "Administrator" || string.IsNullOrWhiteSpace(providedEmails))
            {
                this.ModelState.AddModelError("Provisioner", "The provisioner provided is not valid.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            string[] emails = string.IsNullOrWhiteSpace(providedEmails)
                ? new string[0]
                : ((string)providedEmails).Split(",");

            // Emails are either "Other" provisioners, or office manager(s)
            if (emails.Any() && !EmailService.AreValidEmails(emails))
            {
                this.ModelState.AddModelError("Email(s)", "The email(s) provided are not valid.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (provisionerName == "Other" && emails.Count() > 1)
            {
                this.ModelState.AddModelError("Email", "Other provisioners can only provide a single email address.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

            if (enrollee == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "No enrollee exists for this User Id.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (enrollee.ExpiryDate == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in a finished state.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (!enrollee.CurrentStatus.IsType(StatusType.Editable))
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in an editable state.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            var createdToken = await _certificateService.CreateCertificateAccessTokenAsync(enrollee);

            // Only a few provisioners want emails sent directly, otherwise sent only to managers
            if (provisionerName == "iClinic" || provisionerName == "MediNet" || provisionerName == "Other")
            {
                var provisionerEmail = (provisionerName != "Other")
                    ? await _emailService.GetPharmaNetProvisionerEmailAsync(provisionerName)
                    : emails[0];

                emails = new[] { provisionerEmail };
            }
            else
            {
                provisionerName = null;
            }

            // TODO temporary removed and may be removed permanently
            // await _emailService.SendProvisionerLinkAsync(emails, createdToken, provisionerName);
            await _emailService.SendProvisionerLinkAsync(emails, createdToken);

            await _businessEventService.CreateEmailEventAsync(enrollee.Id, "Provisioner link sent to email(s): " + string.Join(",", emails));

            return(CreatedAtAction(
                       nameof(GetEnrolmentCertificate),
                       new { accessTokenId = createdToken.Id },
                       ApiResponse.Result(createdToken)
                       ));
        }