Ejemplo n.º 1
0
        public async Task<ActionResult> EditTypePart(string id, string name)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
                return Unauthorized();

            var typeDefinition = _contentDefinitionManager.GetTypeDefinition(id);

            if (typeDefinition == null)
            {
                return NotFound();
            }

            var typePartDefinition = typeDefinition.Parts.FirstOrDefault(x => x.Name == name);

            if (typePartDefinition == null)
            {
                return NotFound();
            }

            var typePartViewModel = new EditTypePartViewModel
            {
                Name = typePartDefinition.Name,
                DisplayName = typePartDefinition.DisplayName(),
                Description = typePartDefinition.Description(),
                TypePartDefinition = typePartDefinition,
                Editor = await _contentDefinitionDisplayManager.BuildTypePartEditorAsync(typePartDefinition, this)
            };

            return View(typePartViewModel);
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> EditTypePartPOST(string id, EditTypePartViewModel viewModel)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
                return Unauthorized();

            if (viewModel == null)
            {
                return NotFound();
            }

            var typeDefinition = _contentDefinitionManager.GetTypeDefinition(id);

            if (typeDefinition == null)
            {
                return NotFound();
            }

            var part = typeDefinition.Parts.FirstOrDefault(x => x.Name == viewModel.Name);

            if (part == null)
            {
                return NotFound();
            }

            viewModel.TypePartDefinition = part;

            if (part.PartDefinition.IsReusable())
            {
                if (part.DisplayName() != viewModel.DisplayName)
                {
                    // Prevent null reference exception in validation
                    viewModel.DisplayName = viewModel.DisplayName?.Trim() ?? String.Empty;

                    if (String.IsNullOrWhiteSpace(viewModel.DisplayName))
                    {
                        ModelState.AddModelError("DisplayName", S["The display name can't be empty."]);
                    }

                    if (typeDefinition.Parts.Any(t => t.Name != viewModel.Name && String.Equals(t.DisplayName()?.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase)))
                    {
                        ModelState.AddModelError("DisplayName", S["A part with the same display name already exists."]);
                    }

                    if (!ModelState.IsValid)
                    {
                        _session.Cancel();
                        return View(viewModel);
                    }

                }

                _contentDefinitionService.AlterTypePart(viewModel);
            }

            viewModel.Editor = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, this);

            if (!ModelState.IsValid)
            {
                _session.Cancel();
                return View(viewModel);
            }
            else
            {
                _notifier.Success(T["The \"{0}\" part settings have been saved.", part.DisplayName()]);
            }

            return RedirectToAction("Edit", new { id });
        }
Ejemplo n.º 3
0
        public void AlterTypePart(EditTypePartViewModel typePartViewModel)
        {
            var typeDefinition = typePartViewModel.TypePartDefinition.ContentTypeDefinition;

            _contentDefinitionManager.AlterTypeDefinition(typeDefinition.Name, type =>
            {
                type.WithPart(typePartViewModel.Name, typePartViewModel.TypePartDefinition.PartDefinition, part =>
                {
                    part.WithDisplayName(typePartViewModel.DisplayName);
                    part.WithDescription(typePartViewModel.Description);
                });
            });
        }