Example #1
0
        public ActionResult SubmitDocusign(HomeModel modelUp, HttpPostedFileBase file)
        {
            IHomeModel model = this.HydrateHomeModel(modelUp);

            if (string.IsNullOrWhiteSpace(model.SendToEmail))
            {
                model.ErrorMessage = "You must enter a valid Send To Email value before attempting to send a document.";
                return(View("Index", model));
            }
            if (string.IsNullOrWhiteSpace(model.SendToName))
            {
                model.ErrorMessage = "You must enter a valid Send To Name before attempting to send a document.";
                return(View("Index", model));
            }
            if (model.UseSignatureXY)
            {
                if (!model.SignaturePageNumber.HasValue)
                {
                    model.ErrorMessage = "If directly specifying a signature location, you must enter a valid number into the Page Number field.";
                    return(View("Index", model));
                }
                if (!model.SignatureX.HasValue)
                {
                    model.ErrorMessage = "If directly specifying a signature location, you must enter a valid number into the X Coordinate field.";
                    return(View("Index", model));
                }
                if (!model.SignatureY.HasValue)
                {
                    model.ErrorMessage = "If directly specifying a signature location, you must enter a valid number into the Y Coordinate field.";
                    return(View("Index", model));
                }
            }

            if (file != null && file.ContentLength > 0)
            {
                model.FileName = Path.GetFileName(file.FileName);
                using (MemoryStream ms = new MemoryStream())
                {
                    file.InputStream.CopyTo(ms);
                    model.Document = ms.GetBuffer();
                }
                model.UploadDocumentToDocuSign();
            }
            else
            {
                model.ErrorMessage = "Either a file was not specified or it was empty. Please specify a valid file before attempting to send a document.";
            }

            return(View("Index", model));
        }