private void OnExamineGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            try {
                string nodeTypeAlias = e.Fields["nodeTypeAlias"];

                if (nodeTypeAlias == "Home" || nodeTypeAlias == "LandingPage" || nodeTypeAlias == "TextPage" || nodeTypeAlias == "BlogPost")
                {
                    string value;

                    // Just return now if the "content" field wasn't found
                    if (!e.Fields.TryGetValue("content", out value))
                    {
                        return;
                    }

                    // Parse the raw JSON into an instance of "GridDataModel"
                    GridDataModel grid = GridDataModel.Deserialize(e.Fields["content"]);

                    // Get the searchable text (based on each control in the grid model)
                    e.Fields["content"] = grid.GetSearchableText();
                }
            } catch (Exception ex) {
                // Remember to change the message added to the log. My colleagues typically doesn't,
                // so I occasionally see "MAYDAY! MAYDAY! MAYDAY!" in our logs :(
                LogHelper.Error <SkriftGridExamineIndexer>("MAYDAY! MAYDAY! MAYDAY!", ex);
            }
        }
Example #2
0
        public List <Field> GetFields(int Id, string fieldAlias)
        {
            List <Field> fields      = new List <Field>();
            var          currentNode = contentService.GetById(Id);

            if (currentNode != null)
            {
                var currentForm = currentNode.ContentType.Alias == NodeAlias.FormNode ? currentNode:
                                  contentService.GetAncestors(currentNode).Where(x => x.ContentType.Alias == NodeAlias.FormNode).FirstOrDefault();

                if (currentForm != null)
                {
                    GridDataModel formGrid = GridDataModel.Deserialize(currentForm.GetValue(PropertyAlias.FormGrid).ToString());
                    if (formGrid != null)
                    {
                        fieldAlias = String.IsNullOrEmpty(fieldAlias) ? string.Empty : fieldAlias;
                        var filterField   = !String.IsNullOrWhiteSpace(fieldAlias) ? fieldAlias.Split(',') : null;
                        var allFields     = fieldService.GridControlsAsFields(formGrid.GetAllControls());
                        var filedControls = filterField != null?allFields.Where(f => filterField.Contains(f.FieldType.Type, StringComparer.OrdinalIgnoreCase)) : allFields;

                        fields = filedControls.ToList();
                    }
                }
            }
            return(fields);
        }
        public void TestSample1()
        {
            // Load the JSON
            string json = File.ReadAllText(PathResolver.MapPath("~/Samples/Sample1.json"));

            // Get the Grid model
            GridDataModel model = GridDataModel.Deserialize(json);

            Assert.IsNotNull(model);

            Assert.AreEqual(1, model.Sections.Length);
            Assert.AreEqual(7, model.Sections[0].Rows.Length);

            GridControl[] controls = model.GetAllControls();

            Assert.AreEqual(14, controls.Length);

            Hest(controls[0], "headline", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[1], "quote", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[2], "banner_headline", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[3], "banner_tagline", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[4], "rte", typeof(GridControlRichTextValue));
            Hest(controls[5], "rte", typeof(GridControlRichTextValue));
            Hest(controls[6], "rte", typeof(GridControlRichTextValue));
            Hest(controls[7], "rte", typeof(GridControlRichTextValue));
            Hest(controls[8], "rte", typeof(GridControlRichTextValue));
            Hest(controls[9], "media_wide", typeof(GridControlMediaValue), typeof(GridEditorMediaConfig));
            Hest(controls[10], "rte", typeof(GridControlRichTextValue));
            Hest(controls[11], "rte", typeof(GridControlRichTextValue));
            Hest(controls[12], "rte", typeof(GridControlRichTextValue));
            Hest(controls[13], "media", typeof(GridControlMediaValue), typeof(GridEditorMediaConfig));
        }
 public JsonResult bindUiGrid()
 {
     using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["UIGridDataEntities"].ConnectionString))
     {
         try
         {
             List <GridDataModel> _gridDataModelList = new List <GridDataModel>();
             using (SqlCommand cmd = new SqlCommand())
             {
                 cmd.CommandType = System.Data.CommandType.StoredProcedure;
                 cmd.CommandText = "GridData";
                 cn.Open();
                 cmd.Connection = cn;
                 SqlDataReader dr = cmd.ExecuteReader();
                 while (dr.Read())
                 {
                     GridDataModel _gridDataObj = new GridDataModel();
                     _gridDataObj.Id      = Convert.ToInt32(dr["Id"]);
                     _gridDataObj.age     = Convert.ToString(dr["age"]);
                     _gridDataObj.Name    = Convert.ToString(dr["Name"]);
                     _gridDataObj.gender  = Convert.ToString(dr["gender"]);
                     _gridDataObj.company = Convert.ToString(dr["company"]);
                     _gridDataModelList.Add(_gridDataObj);
                 }
             }
             return(Json(_gridDataModelList, JsonRequestBehavior.AllowGet));
         }
         catch (Exception e)
         {
             return(null);
         }
     }
 }
        public vmBlock_DataRows CreateRows(GridDataModel grid, UmbracoMappingContext context)
        {
            if (grid != null)
            {
                return(new vmBlock_DataRows()
                {
                    Rows = grid.Sections.Any() ? grid.Sections.FirstOrDefault().Rows.Where(x => x.Areas.Any()).Select(y =>
                    {
                        var rowConfig = y.Config.ToDictionary(y.HasConfig).AddCalculatedRowConfig(y);
                        var area = y.Areas.FirstOrDefault();

                        return new vmSub_DataRowsRow()
                        {
                            Items = area.Controls.Select(control =>
                            {
                                var dtgeEditor = control.GetValue <GridControlDtgeValue>();
                                return Content(new GridItemData()
                                {
                                    Control = control, ContextItems = context.Items
                                });
                            }).Where(x => x != null).ToList()
                        };
                    }).ToList() : new List <vmSub_DataRowsRow>()
                });
            }
            else
            {
                return(null);
            }
        }
        public GridViewController(IMainView view, GridDataModel model)
        {
            this.view  = view;
            this.model = model;

            model.GetDataTableBySource(view.GetDataSource());
            ConnectModelAndView();
        }
        /// <summary>
        /// Gets the HTML for the Grid model based on the specified <code>framework</code>.
        /// </summary>
        /// <param name="html">The instance of <code>HtmlHelper</code>.</param>
        /// <param name="model">The Grid model to be rendered.</param>
        /// <param name="framework">The framework used to render the Grid.</param>
        public static HtmlString GetTypedGridHtml(this HtmlHelper html, GridDataModel model, string framework = DefaultFramework) {

            // Return an empty string if the model is empty.
            if (model == null) return new HtmlString(String.Empty);

            // Load the partial view based on the specified framework
            return html.Partial("TypedGrid/" + framework, model);

        }
Example #8
0
        /// <summary>
        /// Gets the HTML for the Grid model based on the specified <paramref name="framework"/>.
        /// </summary>
        /// <param name="html">The instance of <see cref="HtmlHelper"/>.</param>
        /// <param name="model">The Grid model to be rendered.</param>
        /// <param name="framework">The framework used to render the Grid.</param>
        public static HtmlString GetTypedGridHtml(this HtmlHelper html, GridDataModel model, string framework = DefaultFramework)
        {
            // Return an empty string if the model is empty.
            if (model == null)
            {
                return(new HtmlString(String.Empty));
            }

            // Load the partial view based on the specified framework
            return(html.Partial("TypedGrid/" + framework, model));
        }
Example #9
0
        /// <summary>
        /// Gets the HTML for the Grid model based on the specified <paramref name="framework"/>.
        /// </summary>
        /// <param name="html">The instance of <see cref="HtmlHelper"/>.</param>
        /// <param name="property">The property holding the Grid model.</param>
        /// <param name="framework">The framework used to render the Grid.</param>
        public static HtmlString GetTypedGridHtml(this HtmlHelper html, IPublishedProperty property, string framework = DefaultFramework)
        {
            // Get the property value
            GridDataModel value = property.Value as GridDataModel;

            if (value == null)
            {
                return(new HtmlString(String.Empty));
            }

            // Load the partial view based on the specified framework
            return(html.Partial("TypedGrid/" + framework, property.Value));
        }
Example #10
0
        public static bool GridHasContent(IPublishedContent page, string gridAlias)
        {
            var grid = page.GetProperty(gridAlias);

            if (grid != null && grid.HasValue)
            {
                var           content  = grid.DataValue.ToString();
                GridDataModel model    = GridDataModel.Deserialize(content);
                var           controls = model.GetAllControls();

                return(controls != null && controls.Any());
            }

            return(false);
        }
Example #11
0
        public static string GetGridText(string content)
        {
            GridDataModel grid = GridDataModel.Deserialize(content);

            StringBuilder combined = new StringBuilder();

            foreach (GridControl ctrl in grid.GetAllControls())
            {
                switch (ctrl.Editor.Alias)
                {
                case "rte":
                {
                    // Get the HTML value
                    string html = ctrl.GetValue <GridControlRichTextValue>().Value;

                    // Strip any HTML tags so we only have text
                    string text = Regex.Replace(html, "<.*?>", "");

                    // Extra decoding may be necessary
                    text = HttpUtility.HtmlDecode(text);

                    // Now append the text
                    combined.AppendLine(text);

                    break;
                }

                case "media":
                {
                    GridControlMediaValue media = ctrl.GetValue <GridControlMediaValue>();
                    if (media != null)
                    {
                        combined.AppendLine(media.Caption);
                    }
                    break;
                }

                case "headline":
                case "quote":
                {
                    combined.AppendLine(ctrl.GetValue <GridControlTextValue>().Value);
                    break;
                }
                }
            }

            return(combined.ToString());
        }
Example #12
0
        public ActionResult Exec(ExecSqlModel model)
        {
            var res = new GridDataModel();

            try
            {
                res.Data = _service.Exec(model.Query);
            }
            catch (CoreServiceException ex)
            {
                model.Result = ex.Message;
                return(RedirectToAction("Index", model));
            }

            return(View(res));
        }
Example #13
0
        public static string GetStringFromGridModel(GridDataModel grid)
        {
            StringBuilder combined = new StringBuilder();

            foreach (GridControl ctrl in grid.GetAllControls())
            {
                switch (ctrl.Editor.Alias)
                {
                case "rte":
                {
                    // Get the HTML value
                    string html = ctrl.GetValue <GridControlRichTextValue>().HtmlValue.ToString();

                    // Strip any HTML tags so we only have text
                    string text = Regex.Replace(html, "<.*?>", "");

                    // Extra decoding may be necessary
                    text = HttpUtility.HtmlDecode(text);

                    // Now append the text
                    combined.AppendLine(text);

                    break;
                }



                    //case "facts":
                    //	{
                    //		var control = ctrl.GetValue<GridControlFactsValue>();

                    //		string text = control.Headline;

                    //		foreach (var factItem in control.Items)
                    //		{
                    //			text += " " + factItem.Heading;
                    //			text += " " + Regex.Replace(factItem.Text.ToString(), "<.*?>", "");
                    //		}

                    //		combined.AppendLine(text);

                    //		break;
                    //	}
                }
            }
            return(combined.ToString());
        }
        private void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            var domains = container.GetAllInstances <IDomainModel>();

            foreach (var entity in e.PublishedEntities)
            {
                #region validate model in grid
                if (entity.HasProperty(PropertyAlias.GridContent))
                {
                    var json = entity.GetValue <string>(PropertyAlias.GridContent);

                    GridDataModel grid = GridDataModel.Deserialize(json);

                    foreach (var domain in domains)
                    {
                        var gridModels = grid.GetAllControls(domain.GetAliasName());
                        if (gridModels != null && gridModels.Any())
                        {
                            foreach (var gridModel in gridModels)
                            {
                                LeBlenderModel editor = Newtonsoft.Json.JsonConvert.DeserializeObject <LeBlenderModel>(gridModel.JObject.ToString());

                                foreach (var item in editor.Items)
                                {
                                    var model = Mapper.Map(item, domain);
                                    ValidateModel(e, model);
                                }
                            }
                        }
                    }
                }
                #endregion
                #region Validate model
                else
                {
                    var domain = domains.FirstOrDefault(x => x.IsAliasOf(entity.ContentType.Alias));
                    if (domain != null)
                    {
                        var model = Mapper.Map(entity, domain);
                        ValidateModel(e, model);
                    }
                }
                #endregion
            }
        }
Example #15
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            BonusSkins.Register();

            // View
            Form1 mainForm = new Form1();

            // Model
            GridDataModel dataModel = new GridDataModel();

            // Controller
            GridViewController controller = new GridViewController(mainForm, dataModel);

            mainForm.ConnectWithController(controller);

            Application.Run(mainForm);
        }
Example #16
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            GridDataModel grid = value as GridDataModel;

            if (grid == null)
            {
                return;
            }

            var hai = new
            {
                name     = grid.Name,
                sections = from section in grid.Sections
                           select new
                {
                    grid = section.Grid,
                    rows = from row in section.Rows
                           select new
                    {
                        id     = row.Id,
                        name   = row.Name,
                        styles = row.Styles.JObject,
                        config = row.Config.JObject,
                        areas  = from area in row.Areas
                                 select new
                        {
                            grid = area.Grid,
                            //allowAll = area.AllowAll,
                            //allowed = area.Allowed,
                            config   = area.Config.JObject,
                            styles   = area.Styles.JObject,
                            controls = from control in area.Controls
                                       select GetControl(control)
                        }
                    }
                }
            };

            JObject obj = JObject.FromObject(hai);

            obj.WriteTo(writer);
        }
        static void Main(string[] args)
        {
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "", "Example.json");

            // Deserialize the grid data
            GridDataModel gridData = GridDataModel.Deserialize(File.ReadAllText(path));

            Console.WriteLine(path);
            Console.WriteLine();


            if (gridData == null)
            {
                Console.WriteLine("WTF?");
                return;
            }



            foreach (var control in gridData.GetAllControls())
            {
                Console.WriteLine(control.Editor.Alias.PadRight(20) + " => " + (control.Value == null ? "NULL" : control.Value.GetType().FullName));

                if (control.Editor.Alias == "rte")
                {
                    Console.WriteLine();
                    Console.WriteLine("RTE as String:".PadRight(20) + " => " + control.GetValue <GridControlRichTextValue>().Value);
                    Console.WriteLine("RTE as HtmlString:".PadRight(20) + " => " + control.GetValue <GridControlRichTextValue>().HtmlValue);
                    Console.WriteLine();
                }
                else if (control.Editor.Alias == "media")
                {
                    var media = control.GetValue <GridControlMediaValue>();

                    Console.WriteLine();
                    Console.WriteLine("Media:".PadRight(20) + " => " + media.Image + " (" + media.Id + ")");
                    Console.WriteLine();
                }

                //Console.WriteLine( JsonConvert.SerializeObject(control, Formatting.Indented) );
            }
        }
Example #18
0
        /// <summary>
        /// Gets the HTML for the Grid model.
        /// </summary>
        /// <param name="content">The parent content item.</param>
        /// <param name="html">The instance of <see cref="HtmlHelper"/>.</param>
        /// <param name="propertyAlias">The alias of the property.</param>
        /// <param name="framework">The framework used to render the Grid.</param>
        public static HtmlString GetTypedGridHtml(this IPublishedContent content, HtmlHelper html, string propertyAlias, string framework)
        {
            // Get the property with the specifeid alias
            IPublishedProperty property = content.GetProperty(propertyAlias);

            if (property == null)
            {
                throw new NullReferenceException("No property type found with alias " + propertyAlias);
            }

            // Get the property value
            GridDataModel value = property.Value as GridDataModel;

            if (value == null)
            {
                return(new HtmlString(String.Empty));
            }

            // Load the partial view based on the specified framework
            return(html.Partial("TypedGrid/" + framework, property.Value));
        }
        public vmBlock_DataGrid CreateRowsColumns <TConfig>(GridDataModel grid, UmbracoMappingContext context)
        {
            if (grid != null)
            {
                return(new vmBlock_DataGrid()
                {
                    Rows = grid.Sections.Any() ? grid.Sections.FirstOrDefault().Rows.Where(x => x.Areas.Any()).Select(row =>
                    {
                        var rowConfig = row.Config.ToDictionary(row.HasConfig).AddCalculatedRowConfig(row);

                        return new vmSub_DataGridRow()
                        {
                            Config = mapper.Map <TConfig>(rowConfig),
                            Columns = row.Areas.Select(area => {
                                var columnConfig = area.Config.ToDictionary(area.HasConfig).AddCalculatedAreaSettings(row, area);

                                return new vmSub_DataGridColumn()
                                {
                                    GridSize = area.Grid,
                                    Config = mapper.Map <TConfig>(columnConfig),
                                    Items = area.Controls.Select(control =>
                                    {
                                        var dtgeEditor = control.GetValue <GridControlDtgeValue>();
                                        return Content(new GridItemData()
                                        {
                                            Control = control, ContextItems = context.Items
                                        });
                                    }).Where(x => x != null).ToList()
                                };
                            }).ToList()
                        };
                    }).ToList() : new List <vmSub_DataGridRow>()
                });
            }
            else
            {
                return(null);
            }
        }
        public static async Task <GridDataModel <T> > ToGridDataAsync <T>
            (this IQueryable <T> query, GridModel gridModel) where T : class
        {
            var sortExpression = "";

            if (gridModel.SortColumn != null && gridModel.SortColumn.Length > 0)
            {
                var sortDirection = gridModel.SortAscending ? "asc" : "desc";
                sortExpression = $"{gridModel.SortColumn} {sortDirection}";
                query          = query.OrderBy(sortExpression);
            }

            var pagedResult = new GridDataModel <T> {
                RecordsTotal = query.Count()
            };

            query            = query.Skip(gridModel.Skip).Take(gridModel.Take);
            pagedResult.Data = await query.ToListAsync();

            // pagedResult.Draw = gridModel.Draw;
            return(pagedResult);
        }
Example #21
0
        private void IndexGridDataModel(IndexingNodeDataEventArgs e, string propertyValue)
        {
            try
            {
                // Just return/exit now if the value doesn't look like JSON
                if (!propertyValue.StartsWith("{"))
                {
                    return;
                }

                // Parse/deserialize the grid value
                GridDataModel grid = GridDataModel.Deserialize(propertyValue);

                // StringBuilder used for building the new grid value optimized for searching
                var combined = ExamineHelper.GetStringFromGridModel(grid);

                e.Fields[Constants.SkyConstants.Properties.ContentGrid] = combined;
            }
            catch (Exception ex)
            {
                LogHelper.Error <ExamineIndexer>("Exeption in IndexGridDataModel method", ex);
            }
        }
        public async Task <IActionResult> GetAllCloudAccounts()
        {
            var userId = (await TryGetUser(User))?.Id;

            try
            {
                var allParentUserIds = await _dataAccess.GetAllParentUsersIds(userId);

                allParentUserIds.Add(userId);
                var result = await _dataAccess.GetAllCloudAccounts(allParentUserIds);

                var gridResult = new GridDataModel
                {
                    Current  = 1,
                    RowCount = 10,
                    Total    = result.Count,
                    Rows     = result
                };

                return(new ContentResult
                {
                    StatusCode = (int)HttpStatusCode.OK,
                    Content = JsonConvert.SerializeObject(gridResult)
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "GetAllCloudAccounts");
                if (_hostEnvironment.IsDevelopment())
                {
                    throw;
                }

                return(BadRequest(new { Error = e.Message }));
            }
        }
Example #23
0
        public Form GetByNodeId(int Id)
        {
            Form form = new Form();
            IPublishedContent formNode = umbracoHelper.TypedContent(Id);

            if (formNode == null)
            {
                return(null);
            }
            GridDataModel formGrid = formNode.GetPropertyValue <GridDataModel>(PropertyAlias.FormGrid);

            form.Id                 = formNode.Id;
            form.Name               = formNode.Name;
            form.ButtonText         = formNode.HasValue(PropertyAlias.SubmitButton) ? formNode.GetPropertyValue <string>(PropertyAlias.SubmitButton) : string.Empty;
            form.IsSaveLog          = fieldService.GetValueAsBoolean(formNode.HasValue(PropertyAlias.SaveLog) ? formNode.GetPropertyValue <string>(PropertyAlias.SaveLog) : string.Empty);
            form.LogName            = fieldService.PropertyValueAsFields(formNode.HasValue(PropertyAlias.LogName) ? formNode.GetPropertyValue <string>(PropertyAlias.LogName) : string.Empty).FirstOrDefault();
            form.IsEnableSpamFilter = formNode.HasValue(PropertyAlias.SpamFilter) ? formNode.GetPropertyValue <bool>(PropertyAlias.SpamFilter) : false;
            form.DataModel          = formGrid;
            form.Fields             = fieldService.GridControlsAsFields(formGrid.GetAllControls());
            form.Templates          = GetEmailTemplates(formNode);
            form.SuccessMessage     = formNode.HasValue(PropertyAlias.SuccessMessage) ? formNode.GetPropertyValue <string>(PropertyAlias.SuccessMessage) : string.Empty;
            form.ErrorMessage       = formNode.HasValue(PropertyAlias.ErrorMessage) ? formNode.GetPropertyValue <string>(PropertyAlias.ErrorMessage) : string.Empty;
            return(form);
        }
        public static bool GridHasContent(GridDataModel GridControlData)
        {
            var hasContent  = false;
            var keepLooking = true;

            while (keepLooking)
            {
                if (GridControlData.Sections.Any())
                {
                    foreach (var section in GridControlData.Sections)
                    {
                        if (section.Rows.Any())
                        {
                            foreach (var row in section.Rows)
                            {
                                if (row.Areas.Any())
                                {
                                    foreach (var col in row.Areas)
                                    {
                                        if (col.Controls.Any())
                                        {
                                            hasContent  = true;
                                            keepLooking = false;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    keepLooking = false;
                                }
                            }
                        }
                        else
                        {
                            keepLooking = false;
                        }
                    }
                }
                else
                {
                    keepLooking = false;
                }
            }


            //var allControls = new List<GridControl>();
            //foreach (var section in GridControlData.Sections)
            //{
            //    foreach (var row in section.Rows)
            //    {
            //        foreach (var col in row.Areas)
            //        {
            //            foreach (var control in col.Controls)
            //            {
            //                allControls.Add(control);
            //            }
            //        }
            //    }
            //}

            //if (allControls.Any())
            //{ hasContent = true; }

            return(hasContent);
        }
Example #25
0
 /// <summary>
 /// Initializes a new instance from the specified <paramref name="grid"/>.
 /// </summary>
 /// <param name="grid">The grid model the new instance should be based on.</param>
 /// <param name="sections">The sections that should be added to the grid.</param>
 public SpaGridModel(GridDataModel grid, IEnumerable <SpaGridSection> sections)
 {
     Name     = grid.Name;
     Sections = sections.ToList();
 }
Example #26
0
 public vmBlock_DataGrid Resolve(TSource source, TDest destination, GridDataModel sourceMember, string memberName, UmbracoMappingContext context)
 {
     return(gridService.CreateRowsColumns(sourceMember, context));
 }
Example #27
0
        /// <summary>
        /// 通用GridData返回数据
        /// </summary>
        /// <param name="TableName"></param>
        /// <returns></returns>
        public ActionResult GetGridData()
        {
            string TableName = Request.Params["TableName"].ToString();

            string path = "Domain." + TableName + ",Domain";
            Type   type = Type.GetType(path);

            string Columns = "";

            PropertyInfo[] props = type.GetProperties();
            Dictionary <string, object> Param = new Dictionary <string, object>();

            foreach (var item in props)
            {
                Columns += item.Name + ",";
            }
            Columns = Columns.Substring(0, Columns.Length - 1);
            string sql    = "select " + Columns + " from " + TableName + " ";
            string Params = "";
            Dictionary <string, Object> ParamDic = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(Request.Params["Params"]))
            {
                Params = Request.Params["Params"].ToString();
                string[] ParamsArr = Params.Split('&');
                if (ParamsArr.Count() > 0)
                {
                    sql += " where ";
                    foreach (var item in ParamsArr)
                    {
                        if (!string.IsNullOrEmpty(item.Split('=')[0]))
                        {
                            string Name  = item.Split('=')[0];
                            string Value = item.Split('=')[1];
                            sql += Name + "=@" + Name + " and";
                            ParamDic.Add(Name, Value);
                        }
                    }
                    sql = sql.Substring(0, sql.Length - 3);
                }
            }


            GridDataModel  model       = new GridDataModel();
            List <dynamic> dynamicList = DapperHelper.CreateInstance().SimpleQuery(sql, ParamDic);
            List <Object>  target      = new List <Object>();

            foreach (dynamic dynamicItem in dynamicList)
            {
                object modelObj = Activator.CreateInstance(type);

                foreach (var item in dynamicItem)
                {
                    foreach (var classItem in props)
                    {
                        if (classItem.Name.Equals(item.Key))
                        {
                            classItem.SetValue(modelObj, item.Value, null);
                        }
                    }
                }
                target.Add(modelObj);
            }
            model.Rows  = target;
            model.Total = model.Rows.Count();
            string s = new JavaScriptSerializer().Serialize(model);

            return(Json(model));
        }
Example #28
0
        public void TestSample1()
        {
            // Remove the converter for the Fanoe starter kit
            GridContext.Current.Converters.Remove <FanoeGridConverter>();

            Assert.AreEqual(1, GridContext.Current.Converters.Count);

            // Load the JSON
            string json = File.ReadAllText(PathResolver.MapPath("~/Samples/Sample1.json"));

            // Get the Grid model
            GridDataModel model = GridDataModel.Deserialize(json);

            Assert.IsNotNull(model);

            Assert.AreEqual(1, model.Sections.Length);
            Assert.AreEqual(7, model.Sections[0].Rows.Length);

            GridControl[] controls = model.GetAllControls();

            Assert.AreEqual(14, controls.Length);

            Hest(controls[0], "headline", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[1], "quote", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[2], "banner_headline");
            Hest(controls[3], "banner_tagline");
            Hest(controls[4], "rte", typeof(GridControlRichTextValue));
            Hest(controls[5], "rte", typeof(GridControlRichTextValue));
            Hest(controls[6], "rte", typeof(GridControlRichTextValue));
            Hest(controls[7], "rte", typeof(GridControlRichTextValue));
            Hest(controls[8], "rte", typeof(GridControlRichTextValue));
            Hest(controls[9], "media_wide");
            Hest(controls[10], "rte", typeof(GridControlRichTextValue));
            Hest(controls[11], "rte", typeof(GridControlRichTextValue));
            Hest(controls[12], "rte", typeof(GridControlRichTextValue));
            Hest(controls[13], "media", typeof(GridControlMediaValue), typeof(GridEditorMediaConfig));

            {
                Assert.AreEqual(JsonConvert.SerializeObject(model, Formatting.None), model.JObject.ToString(Formatting.None));
                Assert.AreEqual(JsonConvert.SerializeObject(model.Sections[0], Formatting.None), model.Sections[0].JObject.ToString(Formatting.None));

                GridRow row = model.Sections[0].Rows[6];
                Assert.AreEqual("Hest", row.Name);
                Assert.AreEqual(2, row.Areas.Length);
                Assert.AreEqual(true, row.HasAreas);
                Assert.AreEqual(0, row.Styles.Count);
                Assert.AreEqual(1, row.Config.Count);
                Assert.AreEqual("dark", row.Config["class"]);
                Assert.AreEqual(JsonConvert.SerializeObject(row, Formatting.None), row.JObject.ToString(Formatting.None));

                GridArea area1 = model.Sections[0].Rows[6].Areas[0];
                Assert.AreEqual(4, area1.Grid);
                Assert.AreEqual(1, area1.Controls.Length);
                Assert.AreEqual("Hest", area1.Row.Name);
                Assert.AreEqual(4, area1.Grid);
                Assert.AreEqual(1, area1.Config.Count);
                Assert.AreEqual(1, area1.Styles.Count);
                Assert.AreEqual("yellow", area1.Config["class"]);
                Assert.AreEqual("150px", area1.Styles["margin-bottom"]);
                Assert.AreEqual(JsonConvert.SerializeObject(area1, Formatting.None), area1.JObject.ToString(Formatting.None));

                GridArea area2 = model.Sections[0].Rows[6].Areas[1];
                Assert.AreEqual(8, area2.Grid);
                Assert.AreEqual(0, area2.Controls.Length);
                Assert.AreEqual(JsonConvert.SerializeObject(area2, Formatting.None), area2.JObject.ToString(Formatting.None));
            }
        }
 /// <summary>
 /// Gets the model for the typed Grid.
 /// </summary>
 /// <param name="content">The parent content item.</param>
 /// <param name="propertyAlias">The alias of the property.</param>
 public static GridDataModel GetGridModel(this IPublishedContent content, string propertyAlias)
 {
     return(content.Value <GridDataModel>(propertyAlias) ?? GridDataModel.GetEmptyModel());
 }
 /// <inheritdoc />
 public virtual GridSection CreateGridSection(JObject json, GridDataModel grid)
 {
     return(new(json, grid, this));
 }
 /// <summary>
 /// Gets the model for the typed Grid.
 /// </summary>
 /// <param name="content">The parent content item.</param>
 public static GridDataModel GetTypedGrid(this IPublishedContent content)
 {
     return(content.Value <GridDataModel>(DefaultPropertyAlias) ?? GridDataModel.GetEmptyModel());
 }