/// <summary> /// Construct a packet representing this attachment. /// </summary> /// <remarks> /// Messy; confuses construction and transmission. Could do with refactoring. /// </remarks> /// <param name="attachment">The attachment to represent.</param> /// <returns>A packet which, when transmitted to CRM, will instantiate this attachment.</returns> private object ConstructAttachmentPacket(clsEmailAttachments attachment) { List <RESTObjects.eNameValue> initNoteData = new List <RESTObjects.eNameValue>(); initNoteData.Add(new RESTObjects.eNameValue() { name = "name", value = attachment.DisplayName }); object initNoteDataWebFormat = new { @session = SuiteCRMUserSession.id, @module_name = "Notes", @name_value_list = initNoteData }; var res = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.eNewSetEntryResult>("set_entry", initNoteDataWebFormat); RESTObjects.eNewNoteAttachment note = new RESTObjects.eNewNoteAttachment(); note.ID = res.id; note.FileName = attachment.DisplayName; note.FileCotent = attachment.FileContentInBase64String; object attachmentDataWebFormat = new { @session = SuiteCRMUserSession.id, @note = note }; return(attachmentDataWebFormat); }
public void Save(string strExcludedEmails = "") { try { ArrayList arrCRMContacts = GetValidContactIDs(strExcludedEmails); if (arrCRMContacts.Count > 0) { List <RESTObjects.eNameValue> emailData = new List <RESTObjects.eNameValue>(); emailData.Add(new RESTObjects.eNameValue() { name = "from_addr", value = From }); emailData.Add(new RESTObjects.eNameValue() { name = "to_addrs", value = To.Replace("\n", "") }); emailData.Add(new RESTObjects.eNameValue() { name = "name", value = Subject }); emailData.Add(new RESTObjects.eNameValue() { name = "description", value = Body }); emailData.Add(new RESTObjects.eNameValue() { name = "description_html", value = HTMLBody }); emailData.Add(new RESTObjects.eNameValue() { name = "assigned_user_id", value = clsSuiteCRMHelper.GetUserId() }); emailData.Add(new RESTObjects.eNameValue() { name = "status", value = "archived" }); object contactData = new { @session = SuiteCRMUserSession.id, @module_name = "Emails", @name_value_list = emailData }; var emailResult = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.eNewSetEntryResult>("set_entry", contactData); foreach (string strContactID in arrCRMContacts) { object contacRelationshipData = new { @session = SuiteCRMUserSession.id, @module_name = "Contacts", @module_id = strContactID, @link_field_name = "emails", @related_ids = new string[] { emailResult.id } }; var relResult = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.eNewSetRelationshipListResult>("set_relationship", contacRelationshipData); } //Attachments foreach (clsEmailAttachments objAttachment in Attachments) { //Initialize AddIn attachment List <RESTObjects.eNameValue> initNoteData = new List <RESTObjects.eNameValue>(); initNoteData.Add(new RESTObjects.eNameValue() { name = "name", value = objAttachment.DisplayName }); object initNoteDataWebFormat = new { @session = SuiteCRMUserSession.id, @module_name = "Notes", @name_value_list = initNoteData }; var res = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.eNewSetEntryResult>("set_entry", initNoteDataWebFormat); //upload the attachment RESTObjects.eNewNoteAttachment attachment = new RESTObjects.eNewNoteAttachment(); attachment.ID = res.id; attachment.FileName = objAttachment.DisplayName; attachment.FileCotent = objAttachment.FileContentInBase64String; object attachmentDataWebFormat = new { @session = SuiteCRMUserSession.id, @note = attachment }; var attachmentResult = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.eNewSetEntryResult>("set_note_attachment", attachmentDataWebFormat); //Relate the email and the attachment object contacRelationshipData = new { @session = SuiteCRMUserSession.id, @module_name = "Emails", @module_id = emailResult.id, @link_field_name = "notes", @related_ids = new string[] { attachmentResult.id } }; var rel = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.eNewSetRelationshipListResult>("set_relationship", contacRelationshipData); } } } catch (Exception ex) { _log.Error("clsEmailArchive.Save", ex); throw; } }