Пример #1
0
        public ActionResult SyntaxHighlighterOptions(string Theme, CheckBoxListViewModel selectedBrushes)
        {
            if (!User.IsInRole("SuperAdmin") && !User.IsInRole("Admin"))
            {
                return(RedirectToAction("Index", "Home", new { Area = "" }));
            }

            var userId       = GetUserId();
            var updatedTheme = userId == 1 ? Theme : SettingsRepository.BlogSyntaxTheme;

            SettingsRepository.BlogSyntaxScripts = string.Join("~", selectedBrushes.GetSelectedItems());
            SettingsRepository.BlogSyntaxTheme   = updatedTheme;

            var model = new SyntaxHighlighterViewModel
            {
                Brushes             = selectedBrushes,
                AvailableThemes     = GetAvailableSyntaxThemes(updatedTheme),
                EditThemeAttributes = GetAttributes(userId),
                Title        = SettingsRepository.BlogName,
                IsEnabled    = SettingsRepository.BlogSyntaxHighlighting,
                UpdateStatus = true,
                CanEnable    = GetUserId() == 1
            };

            return(View(model));
        }
Пример #2
0
        private static CheckBoxListViewModel GetModel(List <CategoryEntity> baseList, IEnumerable <CategoryEntity> selectedCategories = null)
        {
            var model = new CheckBoxListViewModel {
                HeaderText = "select categories"
            };
            var checkItems = new List <CheckBoxListItem>();

            baseList.ForEach(category =>
            {
                var item = new CheckBoxListItem
                {
                    Text      = category.CategoryName,
                    Value     = category.CategoryID.ToString(),
                    IsChecked = selectedCategories != null && selectedCategories.Any(c => c.CategoryID == category.CategoryID)
                };
                checkItems.Add(item);
            });

            if (selectedCategories == null)
            {
                var general = checkItems.SingleOrDefault(c => c.Text == "General");
                if (general != null)
                {
                    general.IsChecked = true;
                }
            }

            model.Items = checkItems;
            return(model);
        }
        public IViewComponentResult Invoke(Guid id)
        {
            var items = _viewComponentDataRetrievalService.GetData(id);

            ViewModel = new CheckBoxListViewModel
            {
                Id    = id,
                Items = items
            };

            return(View("Default", ViewModel));
        }
Пример #4
0
        private static List <CategoryEntity> GetSelectedCategories(CheckBoxListViewModel checkBoxListViewModel)
        {
            var categories = new List <CategoryEntity>();

            if (checkBoxListViewModel != null)
            {
                var selectedItems = checkBoxListViewModel.Items.Where(c => c.IsChecked).ToList();
                selectedItems.ForEach(i => categories.Add(new CategoryEntity {
                    CategoryID = Int32.Parse(i.Value)
                }));
            }
            return(categories);
        }
Пример #5
0
        public static ObservableCollection <CheckBoxListViewModel <T> > PrepareListForCheckBoxListView(List <T> elements)
        {
            var res = new ObservableCollection <CheckBoxListViewModel <T> >();

            foreach (var element in elements)
            {
                var checkBoxelement = new CheckBoxListViewModel <T> {
                    Data = element, IsChecked = true
                };
                res.Add(checkBoxelement);
            }
            return(res);
        }
Пример #6
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var models   = new List <CheckBoxListViewModel>();
            var formKeys = controllerContext.HttpContext.Request.Form.AllKeys.ToArray();

            var rootItems = formKeys.Where(s => s.StartsWith("hdrTitle")).ToList();

            if (rootItems.Count == 0)
            {
                return(null);
            }

            foreach (var item in rootItems)
            {
                var hdrValue  = item.Split('_')[1];
                var txtValues = formKeys.Where(s => s.StartsWith("lblLabel_" + hdrValue)).ToArray();
                var valValues = formKeys.Where(s => s.StartsWith("valValue_" + hdrValue)).ToArray();
                var hdnValues = formKeys.Where(s => s.StartsWith("hdnChk_" + hdrValue)).ToArray();

                var model = new CheckBoxListViewModel
                {
                    HeaderText = Regex.Replace(hdrValue, "([a-z])([A-Z])", "$1 $2"),
                    Items      = new List <CheckBoxListItem>()
                };
                for (var index = 0; index < txtValues.Count(); index++)
                {
                    var listItem = new CheckBoxListItem
                    {
                        Text      = bindingContext.GetValue(txtValues[index]),
                        Value     = bindingContext.GetValue(valValues[index]),
                        IsChecked = bool.Parse(bindingContext.GetValue(hdnValues[index]))
                    };

                    model.Items.Add(listItem);
                }

                models.Add(model);
            }

            return(rootItems.Count == 1 ? (object)models.First() : models);
        }
Пример #7
0
        public static CheckBoxListViewModel GetBrushesModel(string basePath, string selectedItems)
        {
            var currentList           = selectedItems.Split('~').ToList();
            var checkBoxListViewModel = new CheckBoxListViewModel {
                HeaderText = "Select Brushes"
            };

            var items = new List <CheckBoxListItem>();
            var files = Directory.GetFiles(basePath, "shBrush*.js");

            files.ToList().ForEach(file =>
            {
                var r1    = new Regex(@"shBrush([A-Za-z0-9\-]+).js");
                var match = r1.Match(Path.GetFileName(file));
                var item  = new CheckBoxListItem {
                    Text = match.Groups[1].Value, Value = match.Groups[1].Value, IsChecked = currentList.Contains(match.Groups[1].Value)
                };
                items.Add(item);
            });

            checkBoxListViewModel.Items = items;

            return(checkBoxListViewModel);
        }
 public IActionResult OnPost(CheckBoxListViewModel viewModel)
 {
     // TODO: Call service that will validate the input and save it somewhere.
     return(RedirectToPage("../../ConversationalForm", new { id = viewModel.Id }));
 }
 public CheckBoxListDemoController()
 {
     CheckBoxListVM = new CheckBoxListViewModel();
 }