Exemplo n.º 1
0
        public ActionResult AddPartsTo(string id)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content type.")))
            {
                return(new HttpUnauthorizedResult());
            }

            var typeViewModel = _contentDefinitionService.GetType(id);

            if (typeViewModel == null)
            {
                return(HttpNotFound());
            }

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

            return(View(viewModel));
        }
Exemplo n.º 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(metadataPartsOnly: false)
                                 .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));
        }
        public ActionResult Edit(string id)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, "Not allowed to edit a content type."))
            {
                return(new HttpUnauthorizedResult());
            }

            var typeViewModel = _contentDefinitionService.GetType(id);

            typeViewModel.AllParts = _contentDefinitionService.GetParts().Select(x => x.Name).ToList();
            if (typeViewModel == null)
            {
                return(HttpNotFound());
            }

            return(View(typeViewModel));
        }