Exemplo n.º 1
0
        public ActionResult RemovePartFromPOST(string id)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("无权限.")))
            {
                return(new HttpUnauthorizedResult());
            }

            var typeViewModel = _contentDefinitionService.GetType(id);

            var viewModel = new RemovePartViewModel();

            if (typeViewModel == null ||
                !TryUpdateModel(viewModel) ||
                !typeViewModel.Parts.Any(p => p.PartDefinition.Name == viewModel.Name))
            {
                return(HttpNotFound());
            }

            _contentDefinitionService.RemovePartFromType(viewModel.Name, typeViewModel.Name);

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

            Services.Notifier.Information(T("内容元件 \"{0}\" 成功移除.", viewModel.Name));

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

            var typeViewModel = _contentDefinitionService.GetType(id);

            var viewModel = new RemovePartViewModel();

            if (typeViewModel == null ||
                !await TryUpdateModelAsync(viewModel) ||
                !typeViewModel.TypeDefinition.Parts.Any(p => p.PartDefinition.Name == viewModel.Name))
            {
                return(NotFound());
            }

            _contentDefinitionService.RemovePartFromType(viewModel.Name, typeViewModel.Name);

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

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

            return(RedirectToAction("Edit", new { id }));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> RemovePart(string id, string name)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Forbid());
            }

            var typeViewModel = _contentDefinitionService.LoadType(id);

            if (typeViewModel == null || !typeViewModel.TypeDefinition.Parts.Any(p => p.Name == name))
            {
                return(NotFound());
            }

            _contentDefinitionService.RemovePartFromType(name, id);

            _notifier.Success(H["The \"{0}\" part has been removed.", name]);

            return(RedirectToAction("Edit", new { id }));
        }
Exemplo n.º 4
0
        public async Task <JsonResult> DestroyTypeContents()
        {
            var temp = this.DeserializeObject <IEnumerable <NewPartVM> >();

            foreach (var item in temp)
            {
                ContentItem DeviceItem = await _contentManager.GetAsync(item.NewID);

                if (_contentDefinitionManager.GetTypeDefinition(item.Name) == null)
                {
                }
                else
                {
                    _contentDefinitionService.RemoveType(item.Name, true);
                    _contentDefinitionService.RemovePartFromType(item.NewDisplayName, "新闻主页");
                }
                await _contentManager.RemoveAsync(DeviceItem);
            }
            return(this.Jsonp(temp));
        }