Пример #1
0
        public HttpResponseMessage GetEnvelopeXMLByCode(int envelopeCode)
        {
            HttpResponseMessage responseToClient = new HttpResponseMessage();

            Byte[] info;
            Guid   envelopeId;
            var    doc = new XmlDocument();

            try
            {
                System.Collections.Generic.IEnumerable <string> iHeader;
                Request.Headers.TryGetValues("AuthToken", out iHeader);
                string authToken = iHeader.ElementAt(0);
                using (var dbContext = new eSignEntities())
                {
                    UserTokenRepository tokenRepository    = new UserTokenRepository(dbContext);
                    EnvelopeRepository  envelopeRepository = new EnvelopeRepository(dbContext);
                    string userEmail = tokenRepository.GetUserEmailByToken(authToken);
                    Guid   UserId    = tokenRepository.GetUserProfileUserIDByID(tokenRepository.GetUserProfileIDByEmail(userEmail));
                    string eId       = envelopeRepository.GetEnvelopeIdByDisplayCode(envelopeCode, UserId);
                    if (string.IsNullOrEmpty(eId))
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.NoContent;
                        responseMessage.StatusMessage = "NoContent";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["NoContent"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.NoContent, responseMessage, Configuration.Formatters.XmlFormatter);
                        return(responseToClient);
                    }
                    envelopeId = new Guid(eId);
                    Envelope newEnvelope = envelopeRepository.GetEntity(envelopeId);
                    if (newEnvelope == null)
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.NoContent;
                        responseMessage.StatusMessage = "NoContent";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["NoContent"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
                        return(responseToClient);
                    }
                    info = new UTF8Encoding(true).GetBytes(newEnvelope.EnvelopeContent.First().ContentXML);
                    string xml = Encoding.UTF8.GetString(info);
                    doc.LoadXml(xml);

                    responseToClient = Request.CreateResponse(HttpStatusCode.OK, doc, Configuration.Formatters.XmlFormatter);
                    return(responseToClient);
                }
            }
            catch (Exception ex)
            {
                responseToClient         = Request.CreateResponse((HttpStatusCode)422);
                responseToClient.Content = new StringContent(ex.Message, Encoding.Unicode);
                throw new HttpResponseException(responseToClient);
            }
        }
Пример #2
0
        public HttpResponseMessage ResendEmail(int envelopeCode)
        {
            HttpResponseMessage responseToClient = new HttpResponseMessage();
            //eSign.Web.Controllers.DocumentPackageController doc = new Web.Controllers.DocumentPackageController();
            EnvelopeHelperMain objEnvelope = new EnvelopeHelperMain();
            Guid envelopeId;

            try
            {
                System.Collections.Generic.IEnumerable <string> iHeader;
                Request.Headers.TryGetValues("AuthToken", out iHeader);
                string authToken = iHeader.ElementAt(0);
                using (var dbContext = new eSignEntities())
                {
                    //var helper = new eSign.Web.Helpers.EnvelopeHelper();
                    EnvelopeRepository  envelopeRepository = new EnvelopeRepository(dbContext);
                    UserTokenRepository tokenRepository    = new UserTokenRepository(dbContext);
                    string userEmail = tokenRepository.GetUserEmailByToken(authToken);
                    Guid   UserId    = tokenRepository.GetUserProfileUserIDByID(tokenRepository.GetUserProfileIDByEmail(userEmail));
                    string eId       = envelopeRepository.GetEnvelopeIdByDisplayCode(envelopeCode, UserId);
                    if (string.IsNullOrEmpty(eId))
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.NoContent;
                        responseMessage.StatusMessage = "NoContent";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["NoContent"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.NoContent, responseMessage);
                        return(responseToClient);
                    }
                    envelopeId = new Guid(eId);
                    Envelope envelopeObject = envelopeRepository.GetEntity(envelopeId);
                    if (envelopeObject == null)
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.NoContent;
                        responseMessage.StatusMessage = "NoContent";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["NoContent"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
                        return(responseToClient);
                    }
                    if (envelopeObject.StatusID == Constants.StatusCode.Envelope.Incomplete_and_Expired)
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.BadRequest;
                        responseMessage.StatusMessage = "BadRequest";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["IncompleteAndExpired"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.BadRequest, responseMessage);
                        return(responseToClient);
                    }
                    else if (envelopeObject.StatusID == Constants.StatusCode.Envelope.Terminated)
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.BadRequest;
                        responseMessage.StatusMessage = "BadRequest";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["Terminated"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.BadRequest, responseMessage);
                        return(responseToClient);
                    }
                    var JsonResult = objEnvelope.SendmailReminderAPI(Convert.ToString(envelopeId), tokenRepository.GetUserEmailByToken(authToken));
                    if (JsonResult == "All signers has signed the document")
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.BadRequest;
                        responseMessage.StatusMessage = "BadRequest";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["AllSigned"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.BadRequest, responseMessage);
                        return(responseToClient);
                    }
                    else if (JsonResult == "The email has been resent")
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.OK;
                        responseMessage.StatusMessage = "OK";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["MailResend"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
                        return(responseToClient);
                    }
                    else
                    {
                        responseToClient         = Request.CreateResponse((HttpStatusCode)422);
                        responseToClient.Content = new StringContent(JsonResult, Encoding.Unicode);
                        throw new HttpResponseException(responseToClient);
                    }
                }
            }
            catch (Exception ex)
            {
                responseToClient         = Request.CreateResponse((HttpStatusCode)422);
                responseToClient.Content = new StringContent(ex.Message, Encoding.Unicode);
                throw new HttpResponseException(responseToClient);
            }
        }
Пример #3
0
        public HttpResponseMessage GetFinalSignedPDFDocumentHeader(int envelopeCode)
        {
            HttpResponseMessage responseToClient = new HttpResponseMessage();
            var base64String = string.Empty;

            byte[] binaryData = new Byte[102222];
            //eSign.Web.Controllers.DocumentPackageController doc = new Web.Controllers.DocumentPackageController();
            EnvelopeHelperMain objEnvelope = new EnvelopeHelperMain();
            Guid   envelopeId;
            string finalDocumentName = string.Empty;

            try
            {
                System.Collections.Generic.IEnumerable <string> iHeader;
                Request.Headers.TryGetValues("AuthToken", out iHeader);
                string authToken = iHeader.ElementAt(0);
                using (var objectcontext = new eSignEntities())
                {
                    //var helper = new eSign.Web.Helpers.EnvelopeHelper();
                    UserTokenRepository tokenRepository    = new UserTokenRepository(objectcontext);
                    EnvelopeRepository  envelopeRepository = new EnvelopeRepository(objectcontext);
                    string userEmail = tokenRepository.GetUserEmailByToken(authToken);
                    Guid   UserId    = tokenRepository.GetUserProfileUserIDByID(tokenRepository.GetUserProfileIDByEmail(userEmail));
                    string eId       = envelopeRepository.GetEnvelopeIdByDisplayCode(envelopeCode, UserId);
                    finalDocumentName = envelopeRepository.GetFinalDocumentName(new Guid(eId));
                    if (string.IsNullOrEmpty(eId))
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.NoContent;
                        responseMessage.StatusMessage = "NoContent";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["NoContent"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
                        return(responseToClient);
                    }
                    envelopeId = new Guid(eId);
                    Envelope envelopeObject = envelopeRepository.GetEntity(envelopeId);
                    if (envelopeObject == null)
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.NoContent;
                        responseMessage.StatusMessage = "NoContent";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["NoContent"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
                        return(responseToClient);
                    }
                    if (envelopeObject.StatusID == Constants.StatusCode.Envelope.Waiting_For_Signature)
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.BadRequest;
                        responseMessage.StatusMessage = "BadRequest";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["PartialComplete"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
                        return(responseToClient);
                    }
                    else if (envelopeObject.StatusID == Constants.StatusCode.Envelope.Incomplete_and_Expired)
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.BadRequest;
                        responseMessage.StatusMessage = "BadRequest";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["IncompleteAndExpired"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
                        return(responseToClient);
                    }
                    else if (envelopeObject.StatusID == Constants.StatusCode.Envelope.Terminated)
                    {
                        ResponseMessage responseMessage = new ResponseMessage();
                        responseMessage.StatusCode    = HttpStatusCode.BadRequest;
                        responseMessage.StatusMessage = "BadRequest";
                        responseMessage.Message       = Convert.ToString(ConfigurationManager.AppSettings["Terminated"].ToString());
                        responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
                        return(responseToClient);
                    }

                    string permanentPDFFilePath = ConfigurationManager.AppSettings["PermanentPDFPathStart"].ToString() + envelopeId.ToString() + ConfigurationManager.AppSettings["PermanentPDFPathEnd"].ToString();
                    string finalPdfFilePath     = ConfigurationManager.AppSettings["PDFPathStart"].ToString() + envelopeId.ToString() + ConfigurationManager.AppSettings["PDFPathEnd"].ToString();

                    if (System.IO.File.Exists(permanentPDFFilePath))
                    {
                        System.IO.FileStream inFile;
                        inFile     = new System.IO.FileStream(permanentPDFFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        binaryData = new Byte[inFile.Length];
                        long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
                        base64String = Convert.ToBase64String(binaryData, 0, (int)bytesRead);
                        inFile.Close();
                    }
                    else if (System.IO.File.Exists(finalPdfFilePath))
                    {
                        System.IO.FileStream inFile;
                        inFile     = new System.IO.FileStream(finalPdfFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        binaryData = new Byte[inFile.Length];
                        long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
                        base64String = Convert.ToBase64String(binaryData, 0, (int)bytesRead);
                        inFile.Close();
                    }
                    else
                    {
                        var result = objEnvelope.DownloadPDFApi(envelopeObject);
                        System.IO.FileStream inFile;
                        inFile     = new System.IO.FileStream(result, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        binaryData = new Byte[inFile.Length];
                        long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
                        base64String = Convert.ToBase64String(binaryData, 0, (int)bytesRead);
                        inFile.Close();
                    }
                }

                ResponseMessagePDF responseMessagePDF = new ResponseMessagePDF();
                responseMessagePDF.StatusCode    = HttpStatusCode.OK;
                responseMessagePDF.StatusMessage = "OK";
                responseMessagePDF.FileName      = finalDocumentName + ".pdf";
                responseMessagePDF.Message       = "Following is the binary data of pdf.";
                responseMessagePDF.PdfInBinary   = binaryData;
                responseToClient = Request.CreateResponse(HttpStatusCode.OK, responseMessagePDF);
                return(responseToClient);
            }
            catch (Exception ex)
            {
                responseToClient         = Request.CreateResponse((HttpStatusCode)422);
                responseToClient.Content = new StringContent(ex.Message, Encoding.Unicode);
                throw new HttpResponseException(responseToClient);
            }
        }