/// <summary> /// Create a new business object. /// </summary> /// <param name="objectType">Type of business object to create.</param> /// <param name="criteria">Criteria object describing business object.</param> /// <param name="context"> /// <see cref="Server.DataPortalContext" /> object passed to the server. /// </param> public DataPortalResult Create( Type objectType, object criteria, DataPortalContext context) { try { SetContext(context); Authorize(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Create)); DataPortalResult result; DataPortalMethodInfo method = DataPortalMethodCache.GetCreateMethod(objectType, criteria); IDataPortalServer portal; switch (method.TransactionalType) { case TransactionalTypes.EnterpriseServices: portal = new ServicedDataPortal(); try { result = portal.Create(objectType, criteria, context); } finally { ((ServicedDataPortal)portal).Dispose(); } break; case TransactionalTypes.TransactionScope: portal = new TransactionalDataPortal(); result = portal.Create(objectType, criteria, context); break; default: portal = new DataPortalSelector(); result = portal.Create(objectType, criteria, context); break; } return(result); } catch (Csla.Server.DataPortalException ex) { Exception tmp = ex; throw; } catch (Exception ex) { throw new DataPortalException( "DataPortal.Create " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Create", ex), new DataPortalResult()); } finally { ClearContext(context); } }
/// <summary> /// Create a new business object. /// </summary> /// <param name="objectType">Type of business object to create.</param> /// <param name="criteria">Criteria object describing business object.</param> /// <param name="context"> /// <see cref="Server.DataPortalContext" /> object passed to the server. /// </param> public DataPortalResult Create( Type objectType, object criteria, DataPortalContext context) { try { SetContext(context); DataPortalResult result; MethodInfo method = MethodCaller.GetMethod( objectType, "DataPortal_Create", criteria); IDataPortalServer portal; switch (TransactionalType(method)) { case TransactionalTypes.EnterpriseServices: portal = new ServicedDataPortal(); try { result = portal.Create(objectType, criteria, context); } finally { ((ServicedDataPortal)portal).Dispose(); } break; case TransactionalTypes.TransactionScope: portal = new TransactionalDataPortal(); result = portal.Create(objectType, criteria, context); break; default: portal = new SimpleDataPortal(); result = portal.Create(objectType, criteria, context); break; } return(result); } finally { ClearContext(context); } }