public static void Delete(object criteria) { Server.DataPortalResult result; MethodInfo method = MethodCaller.GetMethod( MethodCaller.GetObjectType(criteria), "DataPortal_Delete", criteria); DataPortalClient.IDataPortalProxy proxy; proxy = GetDataPortalProxy(RunLocal(method)); Server.DataPortalContext dpContext = new Server.DataPortalContext(GetPrincipal(), proxy.IsServerRemote); OnDataPortalInvoke(new DataPortalEventArgs(dpContext)); try { result = proxy.Delete(criteria, dpContext); } catch (Server.DataPortalException ex) { result = ex.Result; if (proxy.IsServerRemote) { ApplicationContext.SetGlobalContext(result.GlobalContext); } throw new DataPortalException("DataPortal.Delete " + Resources.Failed, ex.InnerException, result.ReturnObject); } if (proxy.IsServerRemote) { ApplicationContext.SetGlobalContext(result.GlobalContext); } OnDataPortalInvokeComplete(new DataPortalEventArgs(dpContext)); }
/// <summary> /// Gets a reference to the DataPortal_Fetch method for /// the specified business object type. /// </summary> /// <param name="objectType">Type of the business object.</param> /// <param name="criteria">Criteria parameter value.</param> /// <remarks> /// If the criteria parameter value is an integer, that is a special /// flag indicating that the parameter should be considered missing /// (not Nothing/null - just not there). /// </remarks> public static MethodInfo GetFetchMethod(Type objectType, object criteria) { MethodInfo method = null; if (criteria is int) { // an "Integer" criteria is a special flag indicating // that criteria is empty and should not be used method = MethodCaller.GetMethod(objectType, "DataPortal_Fetch"); } else { method = MethodCaller.GetMethod(objectType, "DataPortal_Fetch", criteria); } return(method); }
/// <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> /// <param name="obj">A reference to the business object to be updated.</param> /// <returns>A reference to the updated business object.</returns> public static object Update(object obj) { Server.DataPortalResult result; MethodInfo method; string methodName; if (obj is CommandBase) { methodName = "DataPortal_Execute"; } else if (obj is Core.BusinessBase) { Core.BusinessBase tmp = (Core.BusinessBase)obj; if (tmp.IsDeleted) { methodName = "DataPortal_DeleteSelf"; } else if (tmp.IsNew) { methodName = "DataPortal_Insert"; } else { methodName = "DataPortal_Update"; } } else { methodName = "DataPortal_Update"; } method = MethodCaller.GetMethod(obj.GetType(), methodName); DataPortalClient.IDataPortalProxy proxy; proxy = GetDataPortalProxy(RunLocal(method)); Server.DataPortalContext dpContext = new Server.DataPortalContext(GetPrincipal(), proxy.IsServerRemote); OnDataPortalInvoke(new DataPortalEventArgs(dpContext)); try { result = proxy.Update(obj, dpContext); } catch (Server.DataPortalException ex) { result = ex.Result; if (proxy.IsServerRemote) { ApplicationContext.SetGlobalContext(result.GlobalContext); } throw new DataPortalException( String.Format("DataPortal.Update {0} ({1})", Resources.Failed, ex.InnerException.InnerException), ex.InnerException, result.ReturnObject); } if (proxy.IsServerRemote) { ApplicationContext.SetGlobalContext(result.GlobalContext); } OnDataPortalInvokeComplete(new DataPortalEventArgs(dpContext)); return(result.ReturnObject); }