Пример #1
0
        private List <FileAttachment> GetFileAttachmentsFromPageModel(UploadDocumentPageModel pageModel, int serviceRequestId)
        {
            List <FileAttachment> attachments = null;

            if (pageModel.UploadedFiles.Count > 0)
            {
                attachments = new List <FileAttachment>();

                foreach (var file in pageModel.UploadedFiles)
                {
                    byte[] byteData = file.SelectedFileWithMemoryData.MemoryStreamData.ToArray();

                    var fileName = file.SelectedFile.Name;

                    var fileAttachment = new FileAttachment
                    {
                        ContentType      = file.SelectedFile.Type,
                        Data             = byteData,
                        Name             = file.SelectedFile.Name,
                        ServiceRequestId = serviceRequestId,
                        Size             = byteData.Length
                    };

                    attachments.Add(fileAttachment);
                }
            }

            return(attachments);
        }
        private KeyValuePair <string, string> GetDocumentParameters(UploadDocumentPageModel pageModel)
        {
            // We assume that there is a parameter in the email template called "DOCUMENT"
            // DOCUMENT paremeter value will show up like the following:
            // Document 1: filename.doc
            // Type of document: Seatime Log

            // Document 2: myPhoto.jpg
            // Type of document: Personal Photo


            KeyValuePair <string, string> document_parameter = new KeyValuePair <string, string>();
            string documentValueStr = null;
            int    counter          = 1;

            if (pageModel.UploadedFiles.Count > 0)
            {
                document_parameter = new KeyValuePair <string, string>();

                foreach (var document in pageModel.UploadedFiles)
                {
                    documentValueStr = documentValueStr +
                                       "Document " + counter.ToString() + " " + document.SelectedFile.Name + "<br/>" +
                                       "Type of document: " + document.Description + "<br><br>";
                    counter++;
                }
                document_parameter = new KeyValuePair <string, string>("DOCUMENT", documentValueStr);
            }

            return(document_parameter);
        }
        public async Task SendEmailToApplicant(UploadDocumentPageModel pageModel)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json");
                client.DefaultRequestHeaders.TryAddWithoutValidation("app-jwt", jwt);
                client.DefaultRequestHeaders.TryAddWithoutValidation("api-key", api_key);

                client.BaseAddress = new Uri(base_uri_str);

                var emailTemplate            = GetEmailTemplateFromPageModel(pageModel);
                HttpResponseMessage response = null;

                try
                {
                    response = await client.PostAsJsonAsync <EmailNotificationDTO>(sub_uri, emailTemplate).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();
                    var status = response.StatusCode;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
            }
        }
        public EmailNotificationDTO GetEmailTemplateFromPageModel(UploadDocumentPageModel pageModel)
        {
            // this method uses the email template: "Seafarers_Document_Submission_Email"

            EmailNotificationDTO template = new EmailNotificationDTO();

            template.NotificationTemplateName = "Seafarers_Document_Submission_Email";
            template.ServiceRequestId         = pageModel == null ? 0 : pageModel.MtoaServiceRequestId;
            template.UserId   = 4536;
            template.UserName = "******";
            template.Language = "English";
            template.From     = "*****@*****.**";
            template.To       = pageModel.EmailAddress;
            template.IsHtml   = true;

            template.Attachements = new List <EmailAttachmentDTO>(); // in our email currently, we do not have attachments. But this field can not be null

            var parameters = new List <KeyValuePair <string, string> >();


            parameters.Add(new KeyValuePair <string, string>("Confirmation_Number", pageModel.ConfirmationNumber));
            parameters.Add(new KeyValuePair <string, string>("CDN_Number", pageModel.CdnNumber));
            parameters.Add(new KeyValuePair <string, string>("Phone_Number", pageModel.PhoneNumber));
            parameters.Add(new KeyValuePair <string, string>("Email_Address", pageModel.EmailAddress));
            parameters.Add(new KeyValuePair <string, string>("Selected_CertificateType", pageModel.CertificateType));
            parameters.Add(new KeyValuePair <string, string>("Confirmation_Number", pageModel.ConfirmationNumber));

            var document_param = GetDocumentParameters(pageModel);

            parameters.Add(document_param);

            template.Parameters = parameters;

            #region -- email template parameters
            // We assume that we have following parameters in the given template
            // Confirmation_Number
            //CDN_Number
            //Phone_Number
            //Email_Address
            //Selected_CertificateType

            //DOCUMENT
            //DOCUMENT --this parameter consists of many document fields combined in one string.

            //It is the list of documents in the format of
            //Document 1 FileName.extention
            //Type of document: Document type Entered.
            #endregion --- end of template parameter information

            return(template);
        }
Пример #5
0
        /// <summary>
        ///following method uploads files after getting files from pageModel.
        // this method returns a list of attachment IDs after storing files on MTOA storage. These IDs can be used to retrieving those files at later time.
        // if there is a negative value (-1) in the List<int>, it means that the corresponding file was not uploaded successfully. Like for a virus issue.
        /// <param name="pageModel"></param>
        /// <returns> List<int> which represent the Mtoa file attachment IDs </returns>
        /// </summary>
        public List <int> UploadFilesInPageModelAsync(UploadDocumentPageModel pageModel)
        {
            List <int> fileAttachmentIDs = null;
            // Following is a temporary static serviceRequestId.
            // TODO: serviceRequestId needs to be created at runtime through MTOA Add service request.
            int serviceRequestId = 13844; // this is used for Dev

            var fileAttachments = this.GetFileAttachmentsFromPageModel(pageModel, serviceRequestId);

            fileAttachmentIDs = new List <int>();
            foreach (var file in fileAttachments)
            {
                var storedFileAttachment = this.UploadFile(serviceRequestId, file);
                fileAttachmentIDs.Add(storedFileAttachment.Id);
            }

            return(fileAttachmentIDs);
        }
 public SessionState(UploadDocumentPageModel uploadDocumentPageModel)
 {
     UploadDocumentPage = uploadDocumentPageModel;
 }