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;
 }
        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;
        }
Esempio n. 3
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;
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public ActionResult SyntaxHighlighterOptions(string Theme, CheckBoxListViewModel selectedBrushes)
        {
            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);
        }
Esempio n. 6
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;
 }