/// <summary>
        /// Attempt to save me given these related records and this HTML body, taking note of these previous failures.
        /// </summary>
        /// <param name="relatedRecords">CRM module names/ids of records to which I should be related.</param>
        /// <param name="fails">Any previous failures in attempting to save me.</param>
        /// <returns>An archive result object describing the outcome of this attempt.</returns>
        private ArchiveResult TrySave(IEnumerable <CrmEntity> relatedRecords, Exception[] fails)
        {
            CrmRestServer  restServer  = SuiteCRMUserSession.RestServer;
            SetEntryResult emailResult = restServer.GetCrmResponse <RESTObjects.SetEntryResult>("set_entry",
                                                                                                ConstructPacket(this.HTMLBody));
            ArchiveResult result = ArchiveResult.Success(emailResult.id, fails);

            if (result.IsSuccess)
            {
                LinkRelatedRecords(relatedRecords, emailResult);
                SaveAttachments(emailResult);
            }

            return(result);
        }
Exemple #2
0
        public static string SetEntry(NameValue[] values, string moduleName)
        {
            EnsureLoggedIn();
            object data = new
            {
                @session         = SuiteCRMUserSession.id,
                @module_name     = moduleName,
                @name_value_list = values
            };
            SetEntryResult _result = SuiteCRMUserSession.RestServer.GetCrmResponse <SetEntryResult>("set_entry", data);

            return(_result.id == null ?
                   string.Empty :
                   _result.id.ToString());
        }
        /// <summary>
        /// Sets an entry in CRM and returns the id.
        /// </summary>
        /// <param name="data">The data to set.</param>
        /// <param name="moduleName">The name of the CRM module into which to insert it.</param>
        /// <returns>the CRM id of the object created or modified.</returns>
        public static string SetEntry(NameValue[] values, string moduleName)
        {
            if (values == null || values.Count() == 0)
            {
                throw new MissingValuesException($"Missing values when storing an instance of '{moduleName}'");
            }
            EnsureLoggedIn();
            object data = new
            {
                @session         = SuiteCRMUserSession.id,
                @module_name     = moduleName,
                @name_value_list = values
            };
            SetEntryResult result = SuiteCRMUserSession.RestServer.GetCrmResponse <SetEntryResult>("set_entry", data);

            return(string.IsNullOrEmpty(result.id) ?
                   string.Empty :
                   result.id);
        }