Exemple #1
0
        public ActionResult SendPDF(string formXml, string xsnName, string viewName, string toEmail, string emailBody)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(System.Web.HttpContext.Current);

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
                SP.User spUser = GetSharePointUser(clientContext);

                string internalUserID = null;

                // Store data for processing
                string            tenantID = TokenHelper.GetRealmFromTargetUrl(new Uri(clientContext.Url));
                RequestIdentifier rid      = RequestUtil.AddRequestEntity(PdfRequestType.SendPDF, PdfRequestStatus.InProgress, tenantID, internalUserID);

                PDFRequest response = new PDFRequest();
                response.RequestID   = rid.ID;
                response.RequestType = PdfRequestType.SendPDF;
                response.Status      = PdfRequestStatus.InProgress;
                response.Message     = "";

                BlobUtil bu = null;
                try
                {
                    bu = new BlobUtil();

                    ParameterCollection plist = new ParameterCollection();
                    plist.Add(Parameters.Api, "SendPDF");
                    plist.Add(Parameters.ViewName, viewName ?? "");
                    plist.Add(Parameters.UserID, internalUserID);
                    plist.Add(Parameters.XsnName, xsnName ?? "");
                    plist.Add(Parameters.FromEmail, spUser.Email ?? "");
                    plist.Add(Parameters.ToEmail, toEmail ?? "");
                    plist.Add(Parameters.EmailBody, emailBody ?? "");

                    BlobCollection bc = new BlobCollection();
                    bc.Add("xml", formXml);
                    bc.Add("parameters", plist);
                    bu.StoreRequestArguments(rid.ID, bc);

                    // post to queue
                    PdfServiceQueues.XmlToHtmlClient.AddMessage(rid.ID, internalUserID);
                }
                catch (Exception ex)
                {
                    // Update request status
                    response.Status  = PdfRequestStatus.Error;
                    response.Message = ex.Message;
                    RequestUtil.UpdateRequestStatus(rid.ID, PdfRequestStatus.Error, ex.Message);
                    //PdfServiceQueues.EmailSendClient.AddErrorMessage(requestID, internalUserID.Value, ex.Message);
                }
                finally
                {
                }
                return(new ObjectResult <PDFRequest>(response));
            }
        }