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 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)); }
public async Task <ActionResult> AddPartsToPOST(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Forbid()); } var typeViewModel = _contentDefinitionService.LoadType(id); if (typeViewModel == null) { return(NotFound()); } var viewModel = new AddPartsViewModel(); if (!await TryUpdateModelAsync(viewModel)) { return(await AddPartsTo(id)); } var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName); foreach (var partToAdd in partsToAdd) { _contentDefinitionService.AddPartToType(partToAdd, typeViewModel.Name); await _notifier.SuccessAsync(H["The \"{0}\" part has been added.", partToAdd]); } if (!ModelState.IsValid) { await _documentStore.CancelAsync(); return(await AddPartsTo(id)); } return(RedirectToAction(nameof(Edit), new { id })); }
public ActionResult AddPartsToPOST(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(); if (!TryUpdateModel(viewModel)) { return(AddPartsTo(id)); } var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName); foreach (var partToAdd in partsToAdd) { _contentDefinitionService.AddPartToType(partToAdd, typeViewModel.Name); Services.Notifier.Information(T("The \"{0}\" part has been added.", partToAdd)); } if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(AddPartsTo(id)); } return(RedirectToAction("Edit", new { id })); }
public async Task <ActionResult> AddPartsToPOST(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(new HttpUnauthorizedResult()); } var typeViewModel = _contentDefinitionService.GetType(id); if (typeViewModel == null) { return(HttpNotFound()); } var viewModel = new AddPartsViewModel(); if (!await TryUpdateModelAsync(viewModel)) { return(await AddPartsTo(id)); } var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName); foreach (var partToAdd in partsToAdd) { _contentDefinitionService.AddPartToType(partToAdd, typeViewModel.Name); //Services.Notifier.Information(T("The \"{0}\" part has been added.", partToAdd)); } if (!ModelState.IsValid) { _session.Cancel(); return(await AddPartsTo(id)); } return(RedirectToAction("Edit", new { id })); }