public ActionResult Start(BulkEditViewModel bulkEditViewModel)
        {
            var bulkEditViewModelWithout3 = bulkEditViewModel.PersonModels.Where(p => p.Id != 3).ToList();

            return(View("Index", new BulkEditViewModel()
            {
                PersonModels = bulkEditViewModelWithout3
            }));
        }
Esempio n. 2
0
        public ActionResult Index(BulkEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                bulkEditService.BulkUpdateFields(model);
                return(Redirect("/sitecore/shell/sitecore/client/Applications/Launchpad"));
            }

            return(View(model));
        }
Esempio n. 3
0
        public void BulkUpdateFields(BulkEditViewModel model)
        {
            var root = GetDatabase().GetItem(new ID(model.RootId));

            if (root == null)
            {
                return;
            }

            var children = root.Children.Where(x => x.TemplateID == new TemplateID(new ID(model.TemplateId))).ToList();

            if (children.Any())
            {
                using (new SecurityDisabler())
                {
                    if (Language.TryParse(model.RootLanguage, out var language))
                    {
                        using (new LanguageSwitcher(language))
                        {
                            foreach (var child in children)
                            {
                                child.Editing.BeginEdit();

                                foreach (var field in model.Fields)
                                {
                                    if (!string.IsNullOrEmpty(field.Value))
                                    {
                                        child.Fields[field.Id].Value = field.Value;
                                    }
                                }

                                child.Editing.EndEdit();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public BulkEditViewModel GetBulkEditViewModel(string rootId, string rootLanguage, string templateId)
        {
            var template = GetDatabase().GetTemplate(new ID(templateId));

            var model = new BulkEditViewModel
            {
                RootId       = rootId,
                RootLanguage = rootLanguage,
                TemplateId   = templateId
            };

            var fields = template.Fields.Where(x => !x.Name.StartsWith("__"));

            foreach (var field in fields)
            {
                model.Fields.Add(new BulkEditFieldViewModel
                {
                    Id   = field.ID.ToString(),
                    Name = field.Name
                });
            }

            return(model);
        }
        public static BulkEditViewModel CreateBulkEditViewModel()
        {
            BulkEditViewModel bulkEditViewModel = new BulkEditViewModel();

            bulkEditViewModel.PersonModels.Add(new PersonModel()
            {
                Id   = 1,
                Name = "Christian"
            });
            bulkEditViewModel.PersonModels.Add(new PersonModel()
            {
                Id   = 2,
                Name = "Tobias"
            });
            bulkEditViewModel.PersonModels.Add(new PersonModel()
            {
                Id   = 3,
                Name = "Tina"
            });
            bulkEditViewModel.PersonModels.Add(new PersonModel()
            {
                Id   = 4,
                Name = "Michael"
            });
            bulkEditViewModel.PersonModels.Add(new PersonModel()
            {
                Id   = 5,
                Name = "Nina"
            });
            bulkEditViewModel.PersonModels.Add(new PersonModel()
            {
                Id   = 6,
                Name = "Jens"
            });
            return(bulkEditViewModel);
        }