Example #1
0
        /// <summary>
        /// Saves a model
        /// </summary>
        /// <param name="connTran">Transaction object</param>
        /// <param name="model">The model</param>
        /// <returns>The saved model</returns>
        /// <exception cref="TimeoutException">Throws a TimeoutException if call doesn't complete within specified time duration</exception>
        /// <exception cref="NotSavedException">Throws a NotSavedException if saving fails for any reason</exception>
        /// <remarks>This method is called by the SaveAsync(T model) overload. Calling it directly is unsafe as save data and sync
        /// information will not be wrapped in a transaction which may introduce inconsistencies in data</remarks>
        public virtual async Task <SaveResponse <T> > SaveAsync(SQLiteConnection connTran, T model)
        {
            if (connTran == null)
            {
                return(null);
            }

            await DataAccess.Instance.SaveAsync(model);

            var obj = model as SynchronizableModelBase;

            if (obj != null && typeof(T) != typeof(SyncRecord))
            {
                SyncingController syncingController = new SyncingController();
                return(new SaveResponse <T>(model, await syncingController.SynchronizeOrQueue(connTran, obj)));
            }

            return(new SaveResponse <T>(model, default(PostResponse)));
        }