Beispiel #1
0
        /// <summary>
        /// Sets the templates.
        /// </summary>
        private void SetTemplates()
        {
            ddlTemplate.Items.Clear();
            ddlTemplate.Items.Add(new ListItem());

            int?entityTypeId = cpProvider.SelectedEntityTypeId;

            if (entityTypeId.HasValue)
            {
                var entityType = EntityTypeCache.Read(entityTypeId.Value);
                if (entityType != null)
                {
                    var component = DigitalSignatureContainer.GetComponent(entityType.Name);
                    if (component != null)
                    {
                        var errors    = new List <string>();
                        var templates = component.GetTemplates(out errors);
                        if (templates != null)
                        {
                            foreach (var keyVal in templates.OrderBy(d => d.Value))
                            {
                                ddlTemplate.Items.Add(new ListItem(keyVal.Value, keyVal.Key));
                            }
                        }
                        else
                        {
                            nbEditModeMessage.Text    = string.Format("<ul><li>{0}</li></ul>", errors.AsDelimited("</li><li>"));
                            nbEditModeMessage.Visible = true;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Cancels the document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public bool CancelDocument(SignatureDocument document, out List <string> errorMessages)
        {
            errorMessages = new List <string>();
            if (document == null || document.SignatureDocumentTemplate == null)
            {
                errorMessages.Add("Invalid Document or Template.");
            }

            if (!errorMessages.Any())
            {
                var provider = DigitalSignatureContainer.GetComponent(document.SignatureDocumentTemplate.ProviderEntityType.Name);
                if (provider == null || !provider.IsActive)
                {
                    errorMessages.Add("Digital Signature provider was not found or is not active.");
                }
                else
                {
                    if (provider.CancelDocument(document, out errorMessages))
                    {
                        if (document.Status != SignatureDocumentStatus.Cancelled)
                        {
                            document.LastStatusDate = RockDateTime.Now;
                        }
                        document.Status = SignatureDocumentStatus.Cancelled;

                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Updates the document status.
        /// </summary>
        /// <param name="signatureDocument">The signature document.</param>
        /// <param name="tempFolderPath">The temporary folder path.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public bool UpdateDocumentStatus(SignatureDocument signatureDocument, string tempFolderPath, out List <string> errorMessages)
        {
            errorMessages = new List <string>();
            if (signatureDocument == null)
            {
                errorMessages.Add("Invalid Document.");
            }

            if (signatureDocument.SignatureDocumentTemplate == null)
            {
                errorMessages.Add("Document has an invalid document type.");
            }

            if (!errorMessages.Any())
            {
                var provider = DigitalSignatureContainer.GetComponent(signatureDocument.SignatureDocumentTemplate.ProviderEntityType.Name);
                if (provider == null || !provider.IsActive)
                {
                    errorMessages.Add("Digital Signature provider was not found or is not active.");
                }
                else
                {
                    var originalStatus = signatureDocument.Status;
                    if (provider.UpdateDocumentStatus(signatureDocument, out errorMessages))
                    {
                        if (signatureDocument.Status == SignatureDocumentStatus.Signed && !signatureDocument.BinaryFileId.HasValue)
                        {
                            using (var rockContext = new RockContext())
                            {
                                string documentPath = provider.GetDocument(signatureDocument, tempFolderPath, out errorMessages);
                                if (!string.IsNullOrWhiteSpace(documentPath))
                                {
                                    var        binaryFileService = new BinaryFileService(rockContext);
                                    BinaryFile binaryFile        = new BinaryFile();
                                    binaryFile.Guid             = Guid.NewGuid();
                                    binaryFile.IsTemporary      = false;
                                    binaryFile.BinaryFileTypeId = signatureDocument.SignatureDocumentTemplate.BinaryFileTypeId;
                                    binaryFile.MimeType         = "application/pdf";
                                    binaryFile.FileName         = new FileInfo(documentPath).Name;
                                    binaryFile.ContentStream    = new FileStream(documentPath, FileMode.Open);
                                    binaryFileService.Add(binaryFile);
                                    rockContext.SaveChanges();

                                    signatureDocument.BinaryFileId = binaryFile.Id;

                                    File.Delete(documentPath);
                                }
                            }
                        }

                        if (signatureDocument.Status != originalStatus)
                        {
                            signatureDocument.LastStatusDate = RockDateTime.Now;
                        }
                    }
                }
            }

            return(!errorMessages.Any());
        }
        /// <summary>
        /// Sends the document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="signatureDocumentTemplate">Type of the signature document.</param>
        /// <param name="appliesToPerson">The person.</param>
        /// <param name="assignedToPerson">The assigned to person.</param>
        /// <param name="documentName">Name of the document.</param>
        /// <param name="alternateEmail">The alternate email.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        private bool SendDocument(SignatureDocument document, SignatureDocumentTemplate signatureDocumentTemplate, Person appliesToPerson, Person assignedToPerson, string documentName, string alternateEmail, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            // If document was passed and other values were not, set them from the document
            if (document != null)
            {
                signatureDocumentTemplate = signatureDocumentTemplate ?? document.SignatureDocumentTemplate;
                if (document.AppliesToPersonAlias != null && document.AppliesToPersonAlias.Person != null)
                {
                    appliesToPerson = appliesToPerson ?? document.AppliesToPersonAlias.Person;
                }
                if (document.AssignedToPersonAlias != null && document.AssignedToPersonAlias.Person != null)
                {
                    assignedToPerson = assignedToPerson ?? document.AssignedToPersonAlias.Person;
                    alternateEmail   = !string.IsNullOrWhiteSpace(alternateEmail) ? alternateEmail : document.AssignedToPersonAlias.Person.Email;
                }

                documentName = !string.IsNullOrWhiteSpace(documentName) ? documentName : document.Name;
            }

            if (signatureDocumentTemplate == null)
            {
                errorMessages.Add("Invalid Document Type.");
            }

            if (appliesToPerson == null)
            {
                errorMessages.Add("Invalid Applies To Person.");
            }

            if (assignedToPerson == null)
            {
                errorMessages.Add("Invalid Assigned To Person.");
            }

            if (!errorMessages.Any())
            {
                var provider = DigitalSignatureContainer.GetComponent(signatureDocumentTemplate.ProviderEntityType.Name);
                if (provider == null || !provider.IsActive)
                {
                    errorMessages.Add("Digital Signature provider was not found or is not active.");
                }
                else
                {
                    string email = string.IsNullOrWhiteSpace(alternateEmail) ? assignedToPerson.Email : alternateEmail;
                    if (string.IsNullOrWhiteSpace(email))
                    {
                        errorMessages.Add(string.Format("There is no email address for {0}.", assignedToPerson.FullName));
                    }
                    else
                    {
                        var sendErrors = new List <string>();

                        var rockContext     = this.Context as RockContext;
                        var documentService = new SignatureDocumentService(rockContext);

                        if (document == null)
                        {
                            document = documentService.Queryable()
                                       .Where(d =>
                                              d.SignatureDocumentTemplateId == signatureDocumentTemplate.Id &&
                                              d.AppliesToPersonAlias.PersonId == appliesToPerson.Id &&
                                              d.AssignedToPersonAlias.PersonId == assignedToPerson.Id &&
                                              d.Status != SignatureDocumentStatus.Signed)
                                       .OrderByDescending(d => d.CreatedDateTime)
                                       .FirstOrDefault();
                        }

                        string documentKey = document?.DocumentKey;
                        if (document == null || string.IsNullOrWhiteSpace(documentKey))
                        {
                            documentKey = provider.CreateDocument(signatureDocumentTemplate, appliesToPerson, assignedToPerson, documentName, out sendErrors, true);
                        }
                        else
                        {
                            provider.ResendDocument(document, out sendErrors);
                        }

                        if (document == null)
                        {
                            document = new SignatureDocument();
                            document.SignatureDocumentTemplate   = signatureDocumentTemplate;
                            document.SignatureDocumentTemplateId = signatureDocumentTemplate.Id;
                            document.Name = documentName;
                            document.AppliesToPersonAliasId  = appliesToPerson.PrimaryAliasId;
                            document.AssignedToPersonAliasId = assignedToPerson.PrimaryAliasId;
                            documentService.Add(document);
                        }

                        if (!sendErrors.Any())
                        {
                            document.DocumentKey    = documentKey;
                            document.LastInviteDate = RockDateTime.Now;
                            document.InviteCount    = document.InviteCount + 1;
                            if (document.Status != SignatureDocumentStatus.Sent)
                            {
                                document.LastStatusDate = document.LastInviteDate;
                            }
                            document.Status = SignatureDocumentStatus.Sent;

                            return(true);
                        }
                        else
                        {
                            errorMessages.AddRange(sendErrors);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// Load the SignNow control.
        /// </summary>
        /// <param name="currentRegistrantIndex">The current registrant index</param>
        /// <param name="registrationState">The registration state from RegistrationEntry</param>
        /// <param name="registrationInstanceState">The registration instance</param>
        /// <param name="digitalSignatureComponent">The digital signature component</param>
        /// <returns></returns>
        public bool Load(int currentRegistrantIndex, RegistrationInfo registrationState, RegistrationInstance registrationInstanceState)
        {
            CurrentRegistrantIndex    = currentRegistrantIndex;
            RegistrationState         = registrationState;
            RegistrationInstanceState = registrationInstanceState;

            var provider = DigitalSignatureContainer.GetComponent(RegistrationInstanceState.RegistrationTemplate.RequiredSignatureDocumentTemplate.ProviderEntityType.Name);

            if (provider != null && provider.IsActive)
            {
                DigitalSignatureComponent = provider;
            }
            var registrant = RegistrationState.Registrants[CurrentRegistrantIndex];

            string firstName = RegistrationInstanceState.RegistrationTemplate.RegistrantTerm;

            if (RegistrationState != null && RegistrationState.RegistrantCount > CurrentRegistrantIndex)
            {
                firstName = registrant.GetFirstName(RegistrationInstanceState.RegistrationTemplate);
                string lastName = registrant.GetLastName(RegistrationInstanceState.RegistrationTemplate);
                string email    = registrant.GetEmail(RegistrationInstanceState.RegistrationTemplate);

                object   dateOfBirthObj = registrant.GetPersonFieldValue(RegistrationInstanceState.RegistrationTemplate, RegistrationPersonFieldType.Birthdate);
                DateTime?dateOfBirth    = null;
                if (dateOfBirthObj != null && dateOfBirthObj is DateTime? )
                {
                    dateOfBirth = dateOfBirthObj as DateTime?;
                }

                // If we have a single person, then we check to see if we already have the document
                var           rockContext     = new Rock.Data.RockContext();
                PersonService personService   = new PersonService(rockContext);
                var           possiblePersons = personService.GetByMatch(firstName, lastName, dateOfBirth, email: email);
                if (possiblePersons.Count() == 1)
                {
                    var person                   = possiblePersons.First();
                    var personAliasIds           = person.Aliases.Select(pa => pa.Id).ToList();
                    var signatureDocumentService = new SignatureDocumentService(rockContext);
                    var validSignatureDocuments  = signatureDocumentService.Queryable().Where(sd =>
                                                                                              personAliasIds.Contains(sd.AppliesToPersonAliasId.Value) &&
                                                                                              sd.SignatureDocumentTemplateId == RegistrationInstanceState.RegistrationTemplate.RequiredSignatureDocumentTemplate.Id &&
                                                                                              sd.Status == SignatureDocumentStatus.Signed
                                                                                              ).OrderBy(sd => sd.CreatedDateTime);
                    if (validSignatureDocuments.Any())
                    {
                        registrant.SignatureDocumentId       = validSignatureDocuments.First().Id;
                        registrant.SignatureDocumentKey      = validSignatureDocuments.First().DocumentKey;
                        registrant.SignatureDocumentLastSent = validSignatureDocuments.First().LastInviteDate;
                        return(true);
                    }
                }
            }


            nbDigitalSignature.Heading = "Signature Required";
            nbDigitalSignature.Text    = string.Format(
                "This {0} requires that you sign a {1} for each registrant, please click the button below and then follow the prompts to digitally sign this document for {2}.  This will open the signing request within our digital signature provider's website.  When you have successfully signed this document, you will be returned to this page which will automatically proceed to the next step of your registration.",
                RegistrationInstanceState.RegistrationTemplate.RegistrationTerm,
                RegistrationInstanceState.RegistrationTemplate.RequiredSignatureDocumentTemplate.Name,
                firstName);

            var    errors     = new List <string>();
            string inviteLink = DigitalSignatureComponent.GetInviteLink(RegistrationInstanceState.RegistrationTemplate.RequiredSignatureDocumentTemplate.ProviderTemplateKey, out errors);

            if (!string.IsNullOrWhiteSpace(inviteLink))
            {
                var key = Guid.NewGuid();

                string returnUrl = GlobalAttributesCache.Get().GetValue("PublicApplicationRoot").EnsureTrailingForwardslash() +
                                   ResolveUrl(Request.RawUrl).TrimStart('/');

                // We need to make sure if someone click's back that we don't end up with extra parameters
                var uri = new Uri(returnUrl);
                var qs  = HttpUtility.ParseQueryString(uri.Query);
                qs.Set("registration_key", key.ToString());
                qs.Remove("document_id");
                // Put the URL back together again
                var uriBuilder = new UriBuilder(uri);
                uriBuilder.Query = qs.ToString();

                // Snap off a copy of the viewstate and set the button URL
                hfRegistrantKey.Value = key.ToString();

                hfRequiredDocumentLinkUrl.Value = string.Format("{0}?redirect_uri={1}", inviteLink, uriBuilder.ToString().UrlEncode());
                btnRequiredDocument.Visible     = true;
            }
            else
            {
                nbDigitalSignature.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Danger;
                nbDigitalSignature.Heading             = "Digital Signature Error";
                nbDigitalSignature.Text = string.Format("An Error Occurred Trying to Get Document Link... <ul><li>{0}</li></ul>", errors.AsDelimited("</li><li>"));
            }
            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// Executes the action.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            var    documentTemplateId = GetAttributeValue(action, AttributeKeys.DocumentTemplate).AsIntegerOrNull();
            Person person             = null;
            DigitalSignatureComponent DigitalSignatureComponent = null;

            // get person
            Guid?personAttributeGuid = GetAttributeValue(action, AttributeKeys.Person).AsGuidOrNull();

            if (personAttributeGuid.HasValue)
            {
                Guid?personAliasGuid = action.GetWorkflowAttributeValue(personAttributeGuid.Value).AsGuidOrNull();
                if (personAliasGuid.HasValue)
                {
                    var personAlias = new PersonAliasService(rockContext).Get(personAliasGuid.Value);
                    if (personAlias != null)
                    {
                        person = personAlias.Person;
                    }
                }
            }

            if (person == null)
            {
                errorMessages.Add("There is no person set on the attribute. Please try again.");
                return(false);
            }

            if (string.IsNullOrWhiteSpace(person.Email))
            {
                errorMessages.Add("There is no valid email address set on the person.");
                return(false);
            }

            if (documentTemplateId.HasValue)
            {
                var signatureDocument = new SignatureDocumentService(rockContext)
                                        .Queryable().AsNoTracking()
                                        .Where(d =>
                                               d.SignatureDocumentTemplateId == documentTemplateId.Value &&
                                               d.AppliesToPersonAlias != null &&
                                               d.AppliesToPersonAlias.PersonId == person.Id &&
                                               d.LastStatusDate.HasValue &&
                                               d.Status == SignatureDocumentStatus.Signed &&
                                               d.BinaryFile != null)
                                        .OrderByDescending(d => d.LastStatusDate.Value)
                                        .FirstOrDefault();

                var documentTemplate = new SignatureDocumentTemplateService(rockContext).Get(documentTemplateId.Value);
                if (documentTemplate.ProviderEntityType != null)
                {
                    var provider = DigitalSignatureContainer.GetComponent(documentTemplate.ProviderEntityType.Name);
                    if (provider != null && provider.IsActive)
                    {
                        DigitalSignatureComponent = provider;
                    }
                }

                if (documentTemplate != null && signatureDocument != null)
                {
                    // get the attribute to store the document/file guid
                    var signatureDocumentAttributeGuid = GetAttributeValue(action, AttributeKeys.SignatureDocument).AsGuidOrNull();
                    if (signatureDocumentAttributeGuid.HasValue)
                    {
                        var signatureDocumentAttribute = AttributeCache.Get(signatureDocumentAttributeGuid.Value, rockContext);
                        if (signatureDocumentAttribute != null)
                        {
                            if (signatureDocumentAttribute.FieldTypeId == FieldTypeCache.Get(Rock.SystemGuid.FieldType.FILE.AsGuid(), rockContext).Id)
                            {
                                SetWorkflowAttributeValue(action, signatureDocumentAttributeGuid.Value, signatureDocument.BinaryFile.Guid.ToString());
                                return(true);
                            }
                            else
                            {
                                errorMessages.Add("Invalid field type for signature document attribute set.");
                                return(false);
                            }
                        }
                        else
                        {
                            errorMessages.Add("Invalid signature document attribute set.");
                            return(false);
                        }
                    }
                    else
                    {
                        errorMessages.Add("Signature document attribute must be set.");
                        return(false);
                    }
                }
                else if (DigitalSignatureComponent != null)
                {
                    var sendDocumentTxn = new Rock.Transactions.SendDigitalSignatureRequestTransaction();
                    sendDocumentTxn.SignatureDocumentTemplateId = documentTemplateId.Value;
                    sendDocumentTxn.AppliesToPersonAliasId      = person.PrimaryAliasId ?? 0;
                    sendDocumentTxn.AssignedToPersonAliasId     = person.PrimaryAliasId ?? 0;
                    sendDocumentTxn.DocumentName = string.Format("{0}_{1}", action.Activity.Workflow.Name.RemoveSpecialCharacters(), person.FullName.RemoveSpecialCharacters());
                    sendDocumentTxn.Email        = person.Email;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue(sendDocumentTxn);
                    return(true);
                }
                else
                {
                    errorMessages.Add("There was an error loading the Digital Signature component, please check your document template.");
                    return(false);
                }
            }
            else
            {
                errorMessages.Add("There was no valid document template id set on this action");
                return(false);
            }
        }