コード例 #1
0
        public ActionResult CreatePOST(CreateTypeViewModel viewModel)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("无权限.")))
            {
                return(new HttpUnauthorizedResult());
            }

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

            if (String.IsNullOrWhiteSpace(viewModel.DisplayName))
            {
                ModelState.AddModelError("DisplayName", T("The Display Name name can't be empty.").ToString());
            }

            if (String.IsNullOrWhiteSpace(viewModel.Name))
            {
                ModelState.AddModelError("Name", T("The Content Type Id can't be empty.").ToString());
            }

            if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("Name", T("A type with the same Id already exists.").ToString());
            }

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

            if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("DisplayName", T("A type with the same Display Name already exists.").ToString());
            }

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

            var contentTypeDefinition = _contentDefinitionService.AddType(viewModel.Name, viewModel.DisplayName);

            // adds CommonPart by default
            _contentDefinitionService.AddPartToType("CommonPart", viewModel.Name);

            var typeViewModel = new EditTypeViewModel(contentTypeDefinition);


            Services.Notifier.Information(T("The \"{0}\" content type has been created.", typeViewModel.DisplayName));

            return(RedirectToAction("AddPartsTo", new { id = typeViewModel.Name }));
        }
コード例 #2
0
        public async Task <ActionResult> CreatePOST(CreateTypeViewModel viewModel)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Forbid());
            }

            viewModel.DisplayName = viewModel.DisplayName?.Trim() ?? String.Empty;
            viewModel.Name        = viewModel.Name ?? String.Empty;

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

            if (_contentDefinitionService.LoadTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("DisplayName", S["A type with the same Display Name already exists."]);
            }

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

            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 (_contentDefinitionService.LoadTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("Name", S["A type with the same Technical Name already exists."]);
            }

            if (!ModelState.IsValid)
            {
                await _documentStore.CancelAsync();

                return(View(viewModel));
            }

            var contentTypeDefinition = _contentDefinitionService.AddType(viewModel.Name, viewModel.DisplayName);

            var typeViewModel = new EditTypeViewModel(contentTypeDefinition);

            await _notifier.SuccessAsync(H["The \"{0}\" content type has been created.", typeViewModel.DisplayName]);

            return(RedirectToAction("AddPartsTo", new { id = typeViewModel.Name }));
        }
コード例 #3
0
        public JsonResult CreateTypeContents()
        {
            var temp = this.DeserializeObject <IEnumerable <NewPartVM> >();

            foreach (var item in temp)
            {
                ContentItem DevicesInfoContentItem = _contentManager.New("新闻组管理");
                DevicesInfoContentItem.Alter <NewPart>(x => x.NewDisplayName = item.NewDisplayName);
                DevicesInfoContentItem.Alter <NewPart>(x => x.NewDescription = item.NewDescription);
                DevicesInfoContentItem.Alter <NewPart>(x => x.Classify       = item.Classify);
                item.Name = "ContentType_" + item.NewDisplayName;
                if (_contentDefinitionManager.GetTypeDefinition(item.Name) == null)
                {
                    if (item.Classify == false)
                    {
                        var BodyPartSetting = new BodyPartSettings {
                        };
                        BodyPartSetting.Editor = "Wysiwyg";
                        _contentDefinitionService.AddType(item.Name, item.NewDisplayName);
                        _contentDefinitionManager.AlterTypeDefinition(item.Name, bulid => bulid
                                                                      .Draftable()
                                                                      .Creatable()
                                                                      .Listable()
                                                                      .WithPart("TitlePart")
                                                                      .WithPart("BodyPart", part => part.WithSettings(BodyPartSetting))
                                                                      );
                    }
                    else
                    {
                        var BodyPartSetting = new BodyPartSettings {
                        };
                        BodyPartSetting.Editor = "Wysiwyg";
                        _contentDefinitionManager.AlterTypeDefinition(item.Name, bulid => bulid
                                                                      .DisplayedAs(item.NewDisplayName)
                                                                      .Draftable()
                                                                      .Creatable()
                                                                      .Listable()
                                                                      .WithPart("TitlePart", part => part.WithPosition("2"))
                                                                      .WithPart("BodyPart", part => part.WithSettings(BodyPartSetting).WithPosition("3"))
                                                                      .WithPart("TypeNewClassifyPart", part => part.WithPosition("1"))
                                                                      );
                    }
                }
                DevicesInfoContentItem.Alter <TitlePart>(x => x.Title = item.NewDisplayName);
                DevicesInfoContentItem.Alter <NewPart>(x => x.Name    = item.Name);
                _contentDefinitionManager.GetTypeDefinition(item.Name);
                _contentManager.Create(DevicesInfoContentItem);
                item.NewID = DevicesInfoContentItem.ContentItemId;
            }
            return(this.Jsonp(temp));
        }
コード例 #4
0
        public async Task <ActionResult> CreatePOST(CreateTypeViewModel viewModel)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Unauthorized());
            }

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

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

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

            if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("Name", S["A type with the same Id already exists."]);
            }

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

            if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("DisplayName", S["A type with the same Display Name already exists."]);
            }

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

            var contentTypeDefinition = _contentDefinitionService.AddType(viewModel.Name, viewModel.DisplayName);

            var typeViewModel = new EditTypeViewModel(contentTypeDefinition);


            _notifier.Success(T["The \"{0}\" content type has been created.", typeViewModel.DisplayName]);

            return(RedirectToAction("AddPartsTo", new { id = typeViewModel.Name }));
        }