public ActionResult Sign(string envelopeId, int signerId)
        {
            // read the specific envelope structure
            string jsonFlow = System.IO.File.ReadAllText(
                Server.MapPath("~/App_Data/documentflows/" + envelopeId + "/documentflow.json"));

            DocumentFlow documentflow = Newtonsoft.Json.JsonConvert.DeserializeObject <DocumentFlow>(jsonFlow);
            Signer       signer       = documentflow.Signers.Find(x => x.Id == signerId);

            SignProcess process = new SignProcess()
            {
                EnvelopeId = documentflow.EnvelopeId,
                Owner      = documentflow.Owner,
                Signer     = signer
            };

            // return the template or the current signed document
            if (System.IO.File.Exists(
                    Server.MapPath("~/App_Data/documentflows/" + envelopeId + "/signed.tx")) == true)
            {
                process.Template = "signed.tx";
            }
            else
            {
                process.Template = documentflow.Template;
            }

            return(View(process));
        }
        public ActionResult Overview()
        {
            List <DocumentFlow> DocumentFlows = new List <DocumentFlow>();

            // read all envelope structures
            foreach (string info in Directory.EnumerateDirectories(Server.MapPath("~/App_Data/documentflows/")))
            {
                string       jsonFlow     = System.IO.File.ReadAllText(info + "/documentflow.json");
                DocumentFlow documentflow = Newtonsoft.Json.JsonConvert.DeserializeObject <DocumentFlow>(jsonFlow);

                DocumentFlows.Add(documentflow);
            }

            // return view with envelope structures
            return(View(DocumentFlows));
        }
        public ActionResult SignDocument()
        {
            Request.InputStream.Position = 0;
            System.IO.StreamReader str = new System.IO.StreamReader(Request.InputStream);
            string sBuf = str.ReadToEndAsync().Result;

            SignDocument jsonDocument = JsonConvert.DeserializeObject <SignDocument>(sBuf);

            byte[] doc = Convert.FromBase64String(jsonDocument.Document);

            // create a new ServerTextControl
            using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
            {
                tx.Create();

                // load the signed document
                tx.Load(doc, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

                // save the document as the current signed documet
                tx.Save(Server.MapPath("~/App_Data/documentflows/" + jsonDocument.UniqueId + "/signed.tx"),
                        TXTextControl.StreamType.InternalUnicodeFormat);
            }

            // read the document flow structure
            string jsonFlow = System.IO.File.ReadAllText(
                Server.MapPath("~/App_Data/documentflows/" + jsonDocument.UniqueId + "/documentflow.json"));

            DocumentFlow documentflow = Newtonsoft.Json.JsonConvert.DeserializeObject <DocumentFlow>(jsonFlow);
            Signer       signer       = documentflow.Signers.Find(x => x.Id == int.Parse(jsonDocument.SignerId));

            signer.SignatureComplete = true; // mark as completed

            // save the flow structure
            System.IO.File.WriteAllText(
                Server.MapPath("~/App_Data/documentflows/" + jsonDocument.UniqueId + "/documentflow.json"),
                Newtonsoft.Json.JsonConvert.SerializeObject(documentflow));

            return(new JsonResult()
            {
                Data = true
            });
        }