Beispiel #1
0
        public async Task<ActionResult> AddPartsToPOST(string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
                return Unauthorized();

            var typeViewModel = _contentDefinitionService.GetType(id);

            if (typeViewModel == null)
                return NotFound();

            var viewModel = new AddPartsViewModel();
            if (!await TryUpdateModelAsync(viewModel))
                return await AddPartsTo(id);

            var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName);
            foreach (var partToAdd in partsToAdd)
            {
                _contentDefinitionService.AddPartToType(partToAdd, typeViewModel.Name);
                _notifier.Success(T["The \"{0}\" part has been added.", partToAdd]);
            }

            if (!ModelState.IsValid)
            {
                _session.Cancel();
                return await AddPartsTo(id);
            }

            return RedirectToAction("Edit", new { id });
        }
Beispiel #2
0
        public async Task<ActionResult> AddPartsTo(string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return Unauthorized();
            }

            var typeViewModel = _contentDefinitionService.GetType(id);

            if (typeViewModel == null)
                return NotFound();

            var typePartNames = new HashSet<string>(typeViewModel.TypeDefinition.Parts.Select(p => p.PartDefinition.Name));

            var viewModel = new AddPartsViewModel
            {
                Type = typeViewModel,
                PartSelections = _contentDefinitionService.GetParts(false/*metadataPartsOnly*/)
                    .Where(cpd => !typePartNames.Contains(cpd.Name) && cpd.Settings.ToObject<ContentPartSettings>().Attachable)
                    .Select(cpd => new PartSelectionViewModel { PartName = cpd.Name, PartDisplayName = cpd.DisplayName, PartDescription = cpd.Description })
                    .ToList()
            };

            return View(viewModel);
        }