public TableStateParserTest()
        {
            HttpRequest request = Substitute.For <HttpRequest>();

            _httpContext = Substitute.For <HttpContext>();
            _httpContext.Request.Returns(request);
            _queryPars = Substitute.For <IReadableStringCollection>();
            request.Query.Returns(_queryPars);
            _parser = new TableStateParser();
        }
        /// <summary>
        /// Renders an Mvc Bootstrap Table.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="htmlHelper">Html helper instance.</param>
        /// <param name="model">The model used to render the table.</param>
        /// <returns>Table builder.</returns>
        public static TableBuilder <T> MvcBootstrapTable <T>(this IHtmlHelper htmlHelper, TableModel <T> model)
            where T : class, new()
        {
            TableState tableState = new TableStateParser().Parse(htmlHelper.ViewContext.HttpContext);

            if (model == null)
            {
                throw(new ArgumentNullException("model"));
            }

            return(new TableBuilder <T>(model, new TableRenderer <T>(tableState, new TableNodeParser()), new BuilderFactory(), new TableConfig <T>()));
        }
Example #3
0
        /// <summary>
        /// Adds a table to the card.
        /// </summary>
        /// <param name="configAction">Action to perform table configuration.</param>
        /// <returns>The card builder instance.</returns>
        public MvcCoreBootstrapCardBuilder Table <T>(TableModel <T> model, Action <MvcCoreBootstrapTableBuilder <T> > configAction) where T : new()
        {
            TableState tableState = new TableStateParser().Parse(_httpContext);

            _tableEntities = model.ProcessedEntities as IEnumerable <object>;
            _tableConfig   = new TableConfig();
            _tableRenderer = new TableRenderer <T>(model, _tableConfig, tableState, new TableNodeParser());
            configAction(new MvcCoreBootstrapTableBuilder <T>(model, new BuilderFactory(), _tableConfig));

            _tableConfigHandler.Check(_tableConfig, _tableEntities);
            _tableConfig.ContainerId = _config.Id;

            return(this);
        }
        /// <summary>
        /// Renders an Mvc Core Bootstrap Table.
        /// </summary>
        /// <typeparam name="T">Model entity type.</typeparam>
        /// <param name="htmlHelper">Html helper instance.</param>
        /// <param name="model">The model used to render the contents of the table.</param>
        /// <param name="configAction">Action that implements table configuration.</param>
        /// <returns>Table html markup.</returns>
        public static IHtmlContent MvcCoreBootstrapTable <T>(this IHtmlHelper htmlHelper, TableModel <T> model,
                                                             Action <MvcCoreBootstrapTableBuilder <T> > configAction = null) where T : class, new()
        {
            if (model == null)
            {
                throw(new ArgumentNullException(nameof(model)));
            }

            TableState         tableState            = new TableStateParser().Parse(htmlHelper.ViewContext.HttpContext);
            TableConfig        config                = new TableConfig();
            TableConfigHandler configHandler         = new TableConfigHandler();
            MvcCoreBootstrapTableBuilder <T> builder = new MvcCoreBootstrapTableBuilder <T>(model, new BuilderFactory(), config);

            configAction?.Invoke(builder);
            configHandler.Check(config, model.ProcessedEntities);

            return(new TableRenderer <T>(model, config, tableState, new TableNodeParser()).Render());
        }