public ActionResult CreateVisualFilter(long visualId)
        {
            var visual          = _visualRepository.GetById(visualId);
            var maxDisplayOrder = visual.VisualFilters.Max(p => p.DisplayOrder) ?? 0;
            var visualFilter    = new VisualFilter
            {
                VisualId     = visualId,
                IsNew        = true,
                DisplayOrder = maxDisplayOrder + 1
            };

            _visualFilterRepository.InsertAndCommit(visualFilter);

            var model = new VisualFilterModel();

            model = visualFilter.ToModel();
            var html = this.VisualFilterPanel(model);

            return(Json(new { Id = visualFilter.Id, Html = html }));
        }
        public ActionResult SaveVisualFilter(VisualFilterModel model)
        {
            if (ModelState.IsValid)
            {
                var visualFilter = _visualFilterRepository.GetById(model.Id);
                if (string.IsNullOrEmpty(visualFilter.Name))
                {
                    var filter = _filterRepository.GetById(model.FilterId);
                    model.Name = filter.Name + "_" + Guid.NewGuid();
                }
                //always set IsNew to false when saving
                visualFilter.IsNew = false;
                visualFilter       = model.ToEntity(visualFilter);

                _visualFilterRepository.UpdateAndCommit(visualFilter);
                return(new NullJsonResult());
            }
            else
            {
                return(Json(new { Errors = ModelState.Errors().ToHtmlString() }));
            }
        }
        public string VisualFilterPanel(VisualFilterModel model)
        {
            var html = this.RenderPartialViewToString("_VisualFilterDetails", model);

            return(html);
        }