Ejemplo n.º 1
0
        public static MyRoot GetRoot()
        {
            var myRoot = DataPortal.Fetch <MyRoot>(null);

            myRoot.BusinessRules.CheckRules();
            return(myRoot);
        }
Ejemplo n.º 2
0
 public static MyRoot GetRoot()
 {
     return(DataPortal.Fetch <MyRoot>(null));
 }
Ejemplo n.º 3
0
 public static MyRoot NewEditableRoot()
 {
     return(DataPortal.Create <MyRoot>());
 }
Ejemplo n.º 4
0
 public static void BeginGetReadOnlyList(string filter, EventHandler <DataPortalResult <CustomerList> > callback)
 {
     DataPortal.BeginFetch <CustomerList>(filter, callback);
 }
Ejemplo n.º 5
0
 public static CustomerList GetReadOnlyList(string filter)
 {
     return(DataPortal.Fetch <CustomerList>(filter));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Called by a factory method in a business class to create
 /// a new object, which is loaded with default
 /// values from the database.
 /// </summary>
 /// <param name="objectType">Type of business object to create.</param>
 /// <param name="criteria">Object-specific criteria.</param>
 /// <returns>A new object, populated with default values.</returns>
 public static object Create(Type objectType, object criteria)
 {
     return(DataPortal <object> .Create(objectType, criteria));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Called by a factory method in a business class to create
        /// a new object, which is loaded with default
        /// values from the database.
        /// </summary>
        /// <typeparam name="T">Specific type of the business object.</typeparam>
        /// <param name="criteria">Object-specific criteria.</param>
        /// <returns>A new object, populated with default values.</returns>
        public static T Create <T>(object criteria)
        {
            var dp = new DataPortal <T>();

            return(dp.Create(criteria));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Starts an asynchronous data portal operation to
 /// delete a business object.
 /// </summary>
 /// <typeparam name="T">
 /// Type of business object to delete.
 /// </typeparam>
 /// <param name="criteria">
 /// Criteria describing the object to delete.
 /// </param>
 public static async Task DeleteAsync <T>(object criteria)
     where T : IMobileObject
 {
     var dp = new DataPortal <T>();
     await dp.DeleteAsync(criteria);
 }
Ejemplo n.º 9
0
 internal static void Delete(Type objectType, object criteria)
 {
     DataPortal <object> .Delete(objectType, criteria);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Called by a Shared (static in C#) method in the business class to cause
        /// immediate deletion of a specific object from the database.
        /// </summary>
        /// <param name="criteria">Object-specific criteria.</param>
        public static void Delete <T>(object criteria)
        {
            var dp = new DataPortal <T>();

            dp.Delete(criteria);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Called by the business object's Save() method to
        /// insert, update or delete an object in the database.
        /// </summary>
        /// <remarks>
        /// Note that this method returns a reference to the updated business object.
        /// If the server-side DataPortal is running remotely, this will be a new and
        /// different object from the original, and all object references MUST be updated
        /// to use this new object.
        /// </remarks>
        /// <typeparam name="T">Specific type of the business object.</typeparam>
        /// <param name="obj">A reference to the business object to be updated.</param>
        /// <returns>A reference to the updated business object.</returns>
        public static T Update <T>(T obj)
        {
            var dp = new DataPortal <T>();

            return(dp.Update(obj));
        }
Ejemplo n.º 12
0
 internal static object Fetch(Type objectType, object criteria)
 {
     return(DataPortal <object> .Fetch(objectType, criteria));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Called by a factory method in a business class to retrieve
        /// an object, which is loaded with values from the database.
        /// </summary>
        /// <typeparam name="T">Specific type of the business object.</typeparam>
        /// <param name="criteria">Object-specific criteria.</param>
        /// <returns>An object populated with values from the database.</returns>
        public static T Fetch <T>(object criteria)
        {
            var dp = new DataPortal <T>();

            return(dp.Fetch(criteria));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Starts an asynchronous data portal operation to
        /// create a business object.
        /// </summary>
        /// <typeparam name="T">
        /// Type of business object to create.
        /// </typeparam>
        /// <param name="criteria">
        /// Criteria describing the object to create.
        /// </param>
        public static async Task <T> CreateAsync <T>(object criteria)
        {
            DataPortal <T> dp = new DataPortal <T>();

            return(await dp.CreateAsync(criteria));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Starts an asynchronous data portal operation to
        /// create a business object.
        /// </summary>
        /// <typeparam name="T">
        /// Type of business object to create.
        /// </typeparam>
        public static async Task <T> CreateAsync <T>()
        {
            DataPortal <T> dp = new DataPortal <T>();

            return(await dp.CreateAsync());
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Saves the specified item in the list.
        /// </summary>
        /// <param name="index">Index of item to be saved.</param>
        /// <param name="delete">true if the item should be deleted.</param>
        protected virtual async Task SaveItemAsync(int index, bool delete)
        {
            T   item       = this[index];
            var handleBusy = false;

            if ((item.IsDeleted || delete) || (item.IsValid && item.IsDirty))
            {
                T savable = item;

                // attempt to clone object
                ICloneable cloneable = savable as ICloneable;
                if (cloneable != null)
                {
                    savable = (T)cloneable.Clone();
                    MethodCaller.CallMethodIfImplemented(item, "MarkBusy");
                    handleBusy = true;
                }

                // commit all changes
                int editLevel = savable.EditLevel;
                for (int tmp = 1; tmp <= editLevel; tmp++)
                {
                    savable.AcceptChanges(editLevel - tmp, false);
                }

                if (delete)
                {
                    savable.Delete();
                }

                Exception error  = null;
                T         result = default(T);
                try
                {
                    result = await DataPortal.UpdateAsync <T>((T)savable);
                }
                catch (AggregateException ex)
                {
                    if (ex.InnerExceptions.Count > 0)
                    {
                        error = ex.InnerExceptions[0];
                    }
                    else
                    {
                        error = ex;
                    }
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    if (handleBusy)
                    {
                        MethodCaller.CallMethodIfImplemented(item, "MarkIdle");
                    }
                }
                // update index - this may have changed under the duration of async call
                index = IndexOf(item);
                if (error == null && result != null)
                {
                    if (savable.IsDeleted)
                    {
                        //SafeRemoveItem  will raise INotifyCollectionChanged event
                        SafeRemoveItem(index);
                    }
                    else
                    {
                        for (int tmp = 1; tmp <= editLevel; tmp++)
                        {
                            result.CopyState(tmp, false);
                        }

                        SafeSetItem(index, result);
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, this[index], index));
                    }
                    item.SaveComplete(result);
                    OnSaved(result, null);
                }
                else
                {
                    item.SaveComplete(item);
                    OnSaved(item, error);
                }
            }
        }