Example #1
0
        public async Task <ActionResult> CreatePartPOST(CreatePartViewModel viewModel)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Unauthorized());
            }

            if (_contentDefinitionManager.GetPartDefinition(viewModel.Name) != null)
            {
                ModelState.AddModelError("Name", S["Cannot add part named '{0}'. It already exists.", viewModel.Name]);
            }

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

            var partViewModel = _contentDefinitionService.AddPart(viewModel);

            if (partViewModel == null)
            {
                _notifier.Information(T["The content part could not be created."]);
                return(View(viewModel));
            }

            _notifier.Success(T["The \"{0}\" content part has been created.", partViewModel.Name]);

            return(RedirectToAction("EditPart", new { id = partViewModel.Name }));
        }
        public ActionResult CreatePartPOST(CreatePartViewModel viewModel)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to create a content part.")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (_contentDefinitionManager.GetPartDefinition(viewModel.Name) != null)
            {
                ModelState.AddModelError("Name", T("Cannot add part named '{0}'. It already exists.", viewModel.Name).ToString());
            }

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

            var partViewModel = _contentDefinitionService.AddPart(viewModel);

            if (partViewModel == null)
            {
                Services.Notifier.Error(T("The content part could not be created."));
                return(View(viewModel));
            }

            Services.Notifier.Success(T("The \"{0}\" content part has been created.", partViewModel.Name));
            return(RedirectToAction("EditPart", new { id = partViewModel.Name }));
        }
Example #3
0
        public ActionResult CreatePartPOST(CreatePartViewModel viewModel)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("无权限.")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (_contentDefinitionManager.GetPartDefinition(viewModel.Name) != null)
            {
                ModelState.AddModelError("Name", T("内容元件 '{0}'. 已存在.", viewModel.Name).ToString());
            }

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

            var partViewModel = _contentDefinitionService.AddPart(viewModel);

            if (partViewModel == null)
            {
                Services.Notifier.Information(T("内容元件创建失败,请输入正确的名称."));
                return(View(viewModel));
            }

            Services.Notifier.Information(T("内容元件 \"{0}\" 创建成功.", partViewModel.Name));
            return(RedirectToAction("EditPart", new { id = partViewModel.Name }));
        }
Example #4
0
        public async Task <ActionResult> CreatePartPOST(CreatePartViewModel viewModel)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Forbid());
            }

            viewModel.Name = viewModel.Name ?? String.Empty;

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

            if (_contentDefinitionService.LoadParts(false).Any(p => String.Equals(p.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("Name", S["A part with the same Technical Name already exists."]);
            }

            if (!String.IsNullOrWhiteSpace(viewModel.Name) && !viewModel.Name[0].IsLetter())
            {
                ModelState.AddModelError("Name", S["The Technical Name must start with a letter."]);
            }

            if (!String.Equals(viewModel.Name, viewModel.Name.ToSafeName(), StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("Name", S["The Technical Name contains invalid characters."]);
            }

            if (viewModel.Name.IsReservedContentName())
            {
                ModelState.AddModelError("Name", S["The Technical Name is reserved for internal use."]);
            }

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

            var partViewModel = _contentDefinitionService.AddPart(viewModel);

            if (partViewModel == null)
            {
                await _notifier.InformationAsync(H["The content part could not be created."]);

                return(View(viewModel));
            }

            await _notifier.SuccessAsync(H["The \"{0}\" content part has been created.", partViewModel.Name]);

            return(RedirectToAction(nameof(EditPart), new { id = partViewModel.Name }));
        }
Example #5
0
        public ActionResult CreatePartPOST(CreatePartViewModel viewModel)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to create a content part.")))
            {
                return(new HttpUnauthorizedResult());
            }

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

            var partViewModel = _contentDefinitionService.AddPart(viewModel);

            if (partViewModel == null)
            {
                Services.Notifier.Information(T("The content part could not be created."));
                return(View(viewModel));
            }

            Services.Notifier.Information(T("The \"{0}\" content part has been created.", partViewModel.Name));
            return(RedirectToAction("EditPart", new { id = partViewModel.Name }));
        }