Esempio n. 1
0
        /// <summary>
        /// Saves an Object into the database. Returns true if the Object was successfully saved, false otherwise. The objects status is captured immediately, but the queries are run asynchronously.
        /// </summary>
        /// <param name="p_obj">The Object to save.</param>
        /// <returns>A status object indicating the success/failure of the operation.</returns>
        public async Task <CDBWizardStatus> SaveAsync <T>(T p_obj)
        {
            CObjectMap p_object_map = CObjectMap.Get(p_obj.GetType());

            if (p_object_map.m_p_begin_delete_call_back != null)
            {
                p_object_map.m_p_begin_delete_call_back(p_obj);
            }

            if (p_object_map.m_p_unique_keys.Count == 0)
            {
                throw new Exception("Cannot save Object without any identifying primary keys defined");
            }

            CDBWizardStatus p_status = await p_object_map.SaveObjectAsync(this, p_obj);

            if (!p_status.IsError)
            {
                if (p_object_map.m_p_end_save_call_back != null)
                {
                    p_object_map.m_p_end_save_call_back(p_obj);
                }
                return(p_status);
            }
            return(p_status);
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes an object from the database.
        /// </summary>
        /// <param name="obj">The object that should be deleted from the database.</param>
        /// <returns>A status object indicating the success/failure of the operation</returns>
        public CDBWizardStatus Delete <T>(T obj)
        {
            CObjectMap p_object_map = CObjectMap.Get(obj.GetType());

            if (p_object_map.m_p_begin_delete_call_back != null)
            {
                p_object_map.m_p_begin_delete_call_back(obj);
            }

            if (p_object_map.m_p_unique_keys.Count == 0)
            {
                throw new Exception("Cannot delete Object without any identifying primary keys defined");
            }

            CDBWizardStatus p_status = p_object_map.DeleteObject(this, obj);

            return(p_status);
        }