/// <summary>
        /// Updates existing data in the database, by saving the changes made to the specified record
        /// </summary>
        /// <param name="record">The record to update</param>
        /// <param name="autoFixErrors">Whether to automatically fix any fixable data errors</param>
        /// <param name="autoIgnoreErrors">Whether to automatically ignore any ignorable data errors</param>
        /// <param name="errorsToIgnore">A list of specific errors to ignore, if autoIgnoreErrors is off</param>
        /// <param name="errorsToFix">A list of specific errors to fix, if autoFixErrors is off</param>
        /// <param name="errorsToNotIgnore">A list of specific errors to not ignore, if autoIgnoreErrors is on</param>
        /// <param name="errorsToNotFix">A list of specific errors to not fix, if autoFixErrors is on</param>
        /// <returns>True if the record was successfully updated</returns>
        public bool Update(ApiObject record, bool autoFixErrors = true, bool autoIgnoreErrors = true, string[] errorsToIgnore = null, string[] errorsToFix = null, string[] errorsToNotIgnore = null, string[] errorsToNotFix = null)
        {
            if (record == null) throw new ArgumentNullException("record");

            XElement xml = record.ReduceToChanges();
            XElement errors = GetErrorsXml(autoFixErrors, autoIgnoreErrors, errorsToIgnore, errorsToFix, errorsToNotIgnore, errorsToNotFix);
            xml.Add(errors);
            XElement result;
            HttpStatusCode status = PerformRequest(string.Join("/", "update", record.TableName, record.ID), xml, out result);
            if (status == HttpStatusCode.OK)
            {
                record.ClearChanges();
                return true;
            }
            return false;
        }
        /// <summary>
        /// The Create method saves a record to the database, and returns the ID of the new record.
        /// </summary>
        /// <param name="record">The record to create</param>
        /// <param name="autoFixErrors">Whether to automatically fix any fixable data errors</param>
        /// <param name="autoIgnoreErrors">Whether to automatically ignore any ignorable data errors</param>
        /// <param name="errorsToIgnore">A list of specific errors to ignore, if autoIgnoreErrors is off</param>
        /// <param name="errorsToFix">A list of specific errors to fix, if autoFixErrors is off</param>
        /// <param name="errorsToNotIgnore">A list of specific errors to not ignore, if autoIgnoreErrors is on</param>
        /// <param name="errorsToNotFix">A list of specific errors to not fix, if autoFixErrors is on</param>
        /// <returns>The ID of the record created</returns>
        public int Create(ApiObject record, bool autoFixErrors = true, bool autoIgnoreErrors = true, string[] errorsToIgnore = null, string[] errorsToFix = null, string[] errorsToNotIgnore = null, string[] errorsToNotFix = null)
        {
            if (record == null) throw new ArgumentNullException("record");

            XElement xml = record.ReduceToChanges();
            XElement errors = GetErrorsXml(autoFixErrors, autoIgnoreErrors, errorsToIgnore, errorsToFix, errorsToNotIgnore, errorsToNotFix);
            xml.Add(errors);
            XElement result;
            HttpStatusCode status = PerformRequest(string.Join("/", "create", record.TableName), xml, out result);
            if (status == HttpStatusCode.OK)
            {
                return Convert.ToInt32(result.Element(record.TableName + "ID").Value);
            }
            return -1;
        }
        /// <summary>
        /// Deletes existing data in the database, by deleting the specified record
        /// </summary>
        /// <param name="record">The record to update</param>
        /// <param name="autoFixErrors">Whether to automatically fix any fixable data errors</param>
        /// <param name="autoIgnoreErrors">Whether to automatically ignore any ignorable data errors</param>
        /// <param name="errorsToIgnore">A list of specific errors to ignore, if autoIgnoreErrors is off</param>
        /// <param name="errorsToFix">A list of specific errors to fix, if autoFixErrors is off</param>
        /// <param name="errorsToNotIgnore">A list of specific errors to not ignore, if autoIgnoreErrors is on</param>
        /// <param name="errorsToNotFix">A list of specific errors to not fix, if autoFixErrors is on</param>
        /// <returns>True if the record was succesfully deleted</returns>
        public bool Delete(ApiObject record, bool autoFixErrors = true, bool autoIgnoreErrors = true, string[] errorsToIgnore = null, string[] errorsToFix = null, string[] errorsToNotIgnore = null, string[] errorsToNotFix = null)
        {
            if (record == null) throw new ArgumentNullException("record");

            return Delete(record.TableName, Convert.ToInt32(record.ID), autoFixErrors, autoIgnoreErrors, errorsToIgnore, errorsToFix, errorsToNotIgnore, errorsToNotFix);
        }
Esempio n. 4
0
 /// <summary>
 /// Gets raw values from an ApiObject array
 /// </summary>
 /// <param name="objectArray">Object array to get raw values from.</param>
 /// <returns>Raw value as string</returns>
 public string GetRaw(ApiObject[] objectArray)
 {
     return objectArray[0].m_element.Elements().First().ToString(SaveOptions.None);
 }