Exemplo n.º 1
0
        public Envelope CreateEnvelope(ApplicationUser user, TemplateInfo templateInfo, string parentUserId)
        {
            try
            {
                if (user == null)
                    throw new ArgumentNullException("user");
                if (templateInfo == null)
                    throw new ArgumentNullException("templateInfo");

                var envelope = new Envelope
                {
                    Login = Account,
                    EmailSubject = user.Company,
                    Status = "sent",
                    TemplateId = templateInfo.Id,
                    TemplateRoles = new[]
                    {
                        new TemplateRole
                        {
                            email = user.Email,
                            name = string.Concat(user.FirstName, " ", user.LastName),
                            roleName = "Signer",
                            clientUserId = user.Id
                        }
                    }
                };

                envelope.Create();

                if (envelope.EnvelopeId != null)
                {
                    _context.Envelopes.Add(new Envelopes
                    {
                        EnvelopeId = envelope.EnvelopeId,
                        EnvelopeName = templateInfo.Name,
                        UserId = parentUserId
                    });

                    _context.SaveChanges();

                    return envelope;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return null;
        }
Exemplo n.º 2
0
        public DocumentForSign GetEmbeddedDocument(Envelope envelope, TemplateInfo templateInfo, string returnUrl)
        {
            try
            {
                if (envelope == null)
                    throw new ArgumentNullException("envelope");
                if (templateInfo == null)
                    throw new ArgumentNullException("templateInfo");

                envelope.GetRecipients();
                var signer = envelope.Recipients.signers[0];

                if (signer != null)
                {
                    var documents = envelope.GetDocuments();

                    var envelopeDocument = documents.FirstOrDefault(x => x.name.Contains(templateInfo.Name));

                    if (envelopeDocument != null)
                    {
                        var tabs = new CustomTabs(int.Parse(envelopeDocument.documentId), signer.recipientId, signer.name);

                        envelope.AddTabs(new TabCollection
                        {
                            companyTabs = tabs.CompanyTabs,
                            dateSignedTabs = tabs.dateSignedTabs,
                            signHereTabs = tabs.SignHereTabs,
                            textTabs = tabs.TextTabs
                        });

                        var doc = new DocumentForSign
                        {
                            Document = Template.GetTemplatePreview(templateInfo.Id),
                            DocumentName = templateInfo.Name,
                            EmbeddedUrl = envelope.GetEmbeddedSignerView(returnUrl, signer)
                        };

                        if (!string.IsNullOrEmpty(doc.EmbeddedUrl))
                        {
                            _context.Documents.Add(new DocuSignDocument()
                            {
                                EnvelopeId = envelope.EnvelopeId,
                                EmbeddedUrl = doc.EmbeddedUrl,
                                Status = "sent",
                                UserId = signer.clientUserId
                            });

                            _context.SaveChanges();
                        }

                        return doc;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return null;
        }