/// <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));
        }
Exemple #3
0
        /// <summary>
        /// Display the UI for editing an entity.
        /// </summary>
        /// <param name="entityName"></param>
        /// <param name="entityId"></param>
        /// <param name="clientId"></param>
        public void DisplayEditUI(ScaffoldContext context)
        {
            BoolMessageItem result = _service.Get(context);

            if (result.Success)
            {
                DisplayEntity(context.EntityName, context.ParentControlId, true, result.Item, _propertiesToExclude);
            }
        }
        /// <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);
        }
        private BoolMessageItem Validate(ScaffoldContext ctx)
        {
            int entityId = 0;

            // Validate the entity id as string.
            if (string.IsNullOrEmpty(ctx.EntityId))
            {
                return(new BoolMessageItem(null, true, string.Empty));
            }
            if (Int32.TryParse(ctx.EntityId, out entityId))
            {
                return(new BoolMessageItem(entityId, true, string.Empty));
            }

            string error = "Unable to parse entity id : " + ctx.EntityId;

            ctx.Errors.Add(error);
            return(new BoolMessageItem(null, false, error));
        }
Exemple #7
0
 /// <summary>
 /// Display UI for adding new entity.
 /// </summary>
 /// <param name="entityName"></param>
 /// <param name="clientId"></param>
 public void DisplayAddUI(ScaffoldContext context)
 {
     DisplayEntity(context.EntityName, context.ParentControlId, false, null, _propertiesToExclude);
 }
Exemple #8
0
 /// <summary>
 /// Submit the data for editing the entity.
 /// </summary>
 /// <param name="entityName"></param>
 /// <param name="entityId"></param>
 /// <param name="clientId"></param>
 public void Update(ScaffoldContext context)
 {
     context.PropValues = _scaffoldUtils.GetValuesFromUI(context.EntityName, context.ParentControlId, _propertiesToExclude);
     _service.Update(context);
     _view.AllResultsTable = _service.GetAll(context);
 }
Exemple #9
0
 /// <summary>
 /// Delete the entity.
 /// </summary>
 /// <param name="entityName"></param>
 /// <param name="entityId"></param>
 /// <param name="clientId"></param>
 public void Delete(ScaffoldContext context)
 {
     _service.Delete(context);
     _view.AllResultsTable = _service.GetAll(context);
 }
Exemple #10
0
 /// <summary>
 /// Get all the records for a specific type of business entity.
 /// </summary>
 /// <param name="context"></param>
 public void GetAll(ScaffoldContext context)
 {
     _view.AllResultsTable = _service.GetAll(context);
 }