public ActionResult Sample06()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                var fiDocument = Request.Files["fi_document"];
                var fiSignature = Request.Files["fi_signature"];
                String iframe = "";
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                Groupdocs.Api.Contract.UploadRequestResult upload = null;
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || Request.Files.Count == 0)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample06", null, result);
                }
                else
                {
                    String basePath = Request.Form["basePath"];
                    //Check is base path entered
                    if (basePath.Equals(""))
                    {
                        //If base path empty set base path to the dev server
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    // Upload document for sign to the storage
                    upload = service.UploadFile(fiDocument.FileName, String.Empty, fiDocument.InputStream);
                    // If file uploaded successfuly
                    if (upload.Guid != null)
                    {
                        // Read binary data from InputStream
                        System.IO.BinaryReader reader = new System.IO.BinaryReader(fiSignature.InputStream);
                        // Convert to byte array
                        byte[] bytedata = reader.ReadBytes((Int32)fiSignature.ContentLength);
                        // Convert from byte array to the Base64 string
                        String data = "data:" + fiSignature.ContentType + ";base64," + Convert.ToBase64String(bytedata);
                        //### Create Signer settings object

                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo signerSettings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo();
                        // Activate signature place
                        signerSettings.PlaceSignatureOn = "1";
                        signerSettings.Email = "*****@*****.**";
                        // Set signer name
                        signerSettings.Name = "GroupDocs";
                        // Transfer signature image
                        signerSettings.Data = data;
                        // Set Heifht for signature
                        signerSettings.Height = new decimal(40d);
                        // Set width for signature
                        signerSettings.Width = new decimal(100d);
                        // Set top coordinate for signature
                        signerSettings.Top = new decimal(0.83319);
                        // Set left coordinate for signature
                        signerSettings.Left = new decimal(0.72171);
                        signerSettings.Fields = new System.Collections.Generic.List<Groupdocs.Api.Contract.Signature.SignatureSignFieldSettingsInfo>().ToArray();
                        // Make request to sig document
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentResponse sign = service.SignDocument(upload.Guid, signerSettings);
                        // If document signed
                        if (sign.Status.Equals("Ok"))
                        {
                            System.Threading.Thread.Sleep(5000);
                            Groupdocs.Api.Contract.Signature.SignatureSignDocumentStatusResponse getDocumentStatus = service.GetSignDocumentStatus(sign.Result.JobId);
                            if (getDocumentStatus.Status.Equals("Ok"))
                            {
                                // Generate Embed viewer url with entered file id
                                if (basePath.Equals("https://api.groupdocs.com/v2.0"))
                                {
                                    iframe = "https://apps.groupdocs.com/document-viewer/embed/" + getDocumentStatus.Result.Documents[0].DocumentId;
                                }
                                if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0"))
                                {
                                    iframe = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + getDocumentStatus.Result.Documents[0].DocumentId;
                                }
                                if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0"))
                                {
                                    iframe = "https://stage-api-groupdocs.dynabic.com/document-viewer/embed/" + getDocumentStatus.Result.Documents[0].DocumentId;
                                }
                                if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0"))
                                {
                                    iframe = "https://realtime-apps.groupdocs.com/document-viewer/embed/" + getDocumentStatus.Result.Documents[0].DocumentId;
                                }
                                iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                result.Add("iframe", iframe);
                                // Put to the result's list received GUID.
                                result.Add("guid", getDocumentStatus.Result.Documents[0].DocumentId);
                            }
                            else
                            {
                                // Redirect to viewer with error.
                                message = getDocumentStatus.ErrorMessage;
                                result.Add("error", message);
                                return View("Sample06", null, result);
                            }

                        }
                        // If request returns error
                        else
                        {
                            // Redirect to viewer with error.
                            message = sign.ErrorMessage;
                            result.Add("error", message);
                            return View("Sample06", null, result);
                        }
                    }

                }
                // Redirect to viewer with received result's.
                return View("Sample06", null, result);

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample06");
            }
        }
        public ActionResult Sample39()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                string message = null;
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                //Chekck is email entered, if not sign document with widget
                if (String.IsNullOrEmpty(Request.Form["email"]))
                {
                    //Get data from ajax
                    System.IO.Stream inputStream = Request.InputStream;
                    System.Text.Encoding encoding = Request.ContentEncoding;
                    System.IO.StreamReader reader = new System.IO.StreamReader(inputStream, encoding);
                    string jsonString = reader.ReadToEnd();
                    //Parse json data from ajax
                    var postData = Newtonsoft.Json.Linq.JObject.Parse(jsonString);
                    //Get data from parsed object
                    String clientId = postData["userId"].ToString();
                    String privateKey = postData["privateKey"].ToString();
                    var document = postData["documents"];
                    var signers = postData["signers"];
                    string guid = null;
                    // Check is all needed fields are entered
                    if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey))
                    {
                        // If not all fields entered send error message
                        message = "Please enter all parameters";
                    }
                    else
                    {
                        //Create GroupDocs service
                        GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey);
                        //Create document for signing object
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo[] documentSettings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo[1];
                        documentSettings[0] = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo();
                        documentSettings[0].Name = document[0]["name"].ToString();
                        documentSettings[0].Data = document[0]["data"].ToString();
                        //Create signature object
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo[] signatureSettings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo[1];
                        signatureSettings[0] = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo();
                        signatureSettings[0].Name = signers[0]["name"].ToString();
                        signatureSettings[0].Data = signers[0]["data"].ToString();
                        //Create sign settings info object
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentSettingsInfo settings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSettingsInfo();
                        settings.Documents = documentSettings;
                        settings.Signers = signatureSettings;
                        //Make request to sign document
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentResponse sign = service.SignDocument(settings);
                        if (sign.Status.Equals("Ok"))
                        {
                            //Get job GUID
                            string jobGuid = sign.Result.JobId;
                            int counter = 5;
                            //Check signed document status and get signed document GUID
                            for (int i = 0; i < counter; i++)
                            {
                                System.Threading.Thread.Sleep(5000);
                                Groupdocs.Api.Contract.Signature.SignatureSignDocumentStatusResponse getSignDocumentStatus = service.GetSignDocumentStatus(jobGuid);
                                if (getSignDocumentStatus.Status.Equals("Ok"))
                                {
                                    if (getSignDocumentStatus.Result.Documents[0].Status.ToString() == "Completed")
                                    {
                                        guid = getSignDocumentStatus.Result.Documents[0].DocumentId;
                                        break;
                                    }
                                }
                                else
                                {
                                    message = getSignDocumentStatus.ErrorMessage;
                                }
                            }
                        }
                        else
                        {
                            message = sign.ErrorMessage;
                        }
                    }
                    //Add data to responce json
                    result.Add("error", message);
                    result.Add("guid", guid);
                    result.Add("clientId", clientId);
                    result.Add("privateKey", privateKey);
                    //Create json string and return it to ajax request
                    return Json(serializer.Serialize(result));
                }
                //Check if email entered if so sign document with out widget
                else if (!String.IsNullOrEmpty(Request.Form["email"]))
                {
                    //Get post data
                    String clientId = Request.Form["clientId"];
                    String privateKey = Request.Form["privateKey"];
                    String email = Request.Form["email"];
                    String name = Request.Form["name"];
                    String lastName = Request.Form["lastName"];
                    String callbackUrl = Request.Form["callbackUrl"];
                    var file = Request.Files["file"];
                    String fileName = "";
                    String guid = "";
                    String iframe = "";
                    // Set entered data to the results list
                    result.Add("clientId", clientId);
                    result.Add("privateKey", privateKey);
                    result.Add("email", email);
                    result.Add("firstName", name);
                    result.Add("lastName", lastName);
                    // Check if callbackUrl is not empty
                    if (!String.IsNullOrEmpty(callbackUrl))
                    {
                        result.Add("callbackUrl", callbackUrl);
                    }
                    // Check is all needed fields are entered
                    if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey) || String.IsNullOrEmpty(email)
                        || String.IsNullOrEmpty(lastName) || String.IsNullOrEmpty(name))
                    {
                        // If not all fields entered send error message
                        message = "Please enter all parameters";
                        result.Add("error", message);
                        return View("Sample39", null, result);
                    }
                    else
                    {
                        //path to settings file - temporary save clientId and apiKey like to property file
                        create_info_file(clientId, privateKey, "");
                        String callbackInfo = AppDomain.CurrentDomain.BaseDirectory + "callback_info.txt";
                        if (System.IO.File.Exists(callbackInfo))
                        {
                            System.IO.File.Delete(callbackInfo);
                        }
                        // Create service for Groupdocs account
                        GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey);
                        //Upload local file
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        if (upload.Guid != null)
                        {
                            //If file uploaded return his guid
                            guid = upload.Guid;
                            fileName = upload.AdjustedName;
                            //Check is file uploaded
                            if (!guid.Equals("") && !fileName.Equals(""))
                            {
                                //Create envelope using user id and entered by user name
                                Groupdocs.Api.Contract.Signature.SignatureEnvelopeResponse envelop = service.CreateEnvelope("", "", fileName, guid, false);
                                if (envelop.Status.Equals("Ok"))
                                {
                                    decimal order = new decimal();
                                    decimal dec = new decimal();
                                    //Get role list for curent user
                                    Groupdocs.Api.Contract.Signature.SignatureRolesResponse roles = service.GetSignatureRoles("");
                                    String roleId = "";
                                    //Get id of role which can sign
                                    for (int i = 0; i < roles.Result.Roles.Length; i++)
                                    {
                                        if (roles.Result.Roles[i].Name.Equals("Signer"))
                                        {
                                            roleId = roles.Result.Roles[i].Id;
                                            break;
                                        }
                                    }
                                    //Add recipient to envelope
                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, email, name, lastName, roleId, dec);
                                    if (addRecipient.Status.Equals("Ok"))
                                    {
                                        //Get document from envelop
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse getDocuments = service.GetEnvelopeDocuments(envelop.Result.Envelope.Id);
                                        if (getDocuments.Status.Equals("Ok"))
                                        {
                                            System.Random rand = new System.Random();
                                            String fieldName = "singlSample" + rand.Next(0, 1000);
                                            //Create envelop field settings object (LocationsX,Y max value can bee 1.0)
                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo envelopFieldSettings = new Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo();
                                            envelopFieldSettings.LocationX = new decimal(0.15);
                                            envelopFieldSettings.LocationY = new decimal(0.73);
                                            envelopFieldSettings.LocationWidth = 150;
                                            envelopFieldSettings.LocationHeight = 50;
                                            envelopFieldSettings.Name = fieldName;
                                            envelopFieldSettings.ForceNewField = true;
                                            envelopFieldSettings.Page = 1;
                                            //Add envelop field to the document
                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addFields = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, addRecipient.Result.Recipient.Id, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings);
                                            //Send envelop with callbackUrl url
                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeSendResponse send = service.SendEnvelope(envelop.Result.Envelope.Id, callbackUrl);
                                            //Check is envelope send status
                                            if (send.Status.Equals("Ok"))
                                            {
                                                // Generate Embed viewer url with entered file id
                                                iframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                                iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                                result.Add("iframe", iframe);
                                                return View("Sample39", null, result);
                                            }
                                            //If status failed set error for template
                                            else
                                            {
                                                message = send.ErrorMessage;
                                                result.Add("error", message);
                                                return View("Sample39", null, result);
                                            }
                                        }
                                        //If get document from envelop is failed return error
                                        else
                                        {
                                            message = getDocuments.ErrorMessage;
                                            result.Add("error", message);
                                            return View("Sample39", null, result);
                                        }
                                    }
                                    //If add recipient is failed return error
                                    else
                                    {
                                        message = addRecipient.ErrorMessage;
                                        result.Add("error", message);
                                        return View("Sample39", null, result);
                                    }
                                }
                                //If envelope wasn't created send error
                                else
                                {
                                    message = envelop.ErrorMessage;
                                    result.Add("error", message);
                                    return View("Sample39", null, result);
                                }
                            }
                            // If request return's null return error to the template
                            else
                            {
                                message = "Upload is failed";
                                result.Add("error", message);
                                return View("Sample39", null, result);
                            }
                        }
                        else
                        {
                            //If file wasn't uploaded return error
                            message = "Something wrong with upload";
                            result.Add("error", message);
                            return View("Sample39", null, result);
                        }
                    }

                }
                return View("Sample39");
            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample39");
            }
        }