/// <summary> /// Retrieve datatable containing all the records for the specified entity. /// </summary> /// <param name="entity"></param> /// <param name="clientId"></param> /// <returns></returns> public DataTable GetAll(ScaffoldContext ctx) { EntityManager entitySvc = new EntityManager(); EntityServiceContext entityServiceContext = CreateContext(ctx, false, false, false).Item as EntityServiceContext; BoolMessageItem result = entitySvc.GetAll(entityServiceContext); if (!result.Success) { return(null); } IList allItems = result.Item as IList; DataTable table = null; // Check for 0 results. if (allItems != null) { // If we have results, convert each object in the list // to a record, so we're effectively converting the object list // to a DataTable. if (allItems.Count > 0) { IList <PropertyInfo> properties = GetProperties(ctx.EntityName); table = DataUtils.ConvertPropertyCollectionToDataTable(allItems, properties); } } return(table); }
private BoolMessageItem CreateContext(ScaffoldContext scaffoldContext, bool parseEntityId, bool createEntity, bool transferScaffoldUIValuesToEntity) { int entityId = 0; // Convert the strin entity id to an integer entity id. if (parseEntityId) { BoolMessageItem parseResult = Validate(scaffoldContext); if (!parseResult.Success) { return(parseResult); } entityId = (int)parseResult.Item; } // The type of the entity. Type typ = Type.GetType(scaffoldContext.EntityName); object entity = createEntity ? Activator.CreateInstance(typ) : null; EntityServiceContext enCtx = new EntityServiceContext(typ, entityId, entity); enCtx.Errors = scaffoldContext.Errors; // Transfer the values from the Dynamically generated Scaffold UI to the entity. if (createEntity && transferScaffoldUIValuesToEntity) { // Set the entity properties using the properties supplied. ReflectionUtils.SetProperties <object>(enCtx.Item, scaffoldContext.PropValues); } return(new BoolMessageItem(enCtx, true, string.Empty)); }
/// <summary> /// Retrieve the entity with the specified id, given the entityType /// </summary> /// <param name="entityName">"Category"</param> /// <param name="id">"1" Id of a specific entity.</param> /// <returns></returns> public BoolMessageItem Get(ScaffoldContext ctx) { BoolMessageItem creationResult = CreateContext(ctx, true, false, false); if (!creationResult.Success) { return(creationResult); } EntityServiceContext entityActionContext = creationResult.Item as EntityServiceContext; EntityManager entitySvc = new EntityManager(); BoolMessageItem result = entitySvc.Get(entityActionContext); return(result); }
/// <summary> /// Update the specific entity with property values specified. /// </summary> /// <param name="entityName">"Category"</param> /// <param name="propValues">List of key value pairs. /// Where the key is the property name, and the value is a string /// representation of the property value.</param> public BoolMessage Create(ScaffoldContext ctx) { BoolMessageItem creationResult = CreateContext(ctx, false, true, true); if (!creationResult.Success) { return(creationResult); } EntityServiceContext entityActionContext = creationResult.Item as EntityServiceContext; // Create the entity using the entity service. EntityManager service = new EntityManager(); BoolMessage result = service.Create(entityActionContext); return(result); }