private async Task <IActionResult> CreatePOST(string id, string containerId, string returnUrl, CompleteActionOutCome onCompleteSubmitAction, Func <ContentItem, Task> conditionallyPublish) { var contentItem = await _contentManager.NewAsync(id); // Set the current user as the owner to check for ownership permissions on creation contentItem.Owner = User.Identity.Name; if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, contentItem)) { return(Unauthorized()); } var model = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, true); if (!ModelState.IsValid) { _session.Cancel(); return(View(model)); } if (!string.IsNullOrEmpty(containerId)) { //add parent content reference var rootContentItem = await _contentManager.GetAsync(containerId, VersionOptions.Latest); if (rootContentItem != null) { await _listContainerService.AddChildContentItemReference(rootContentItem, contentItem); } } await _contentManager.CreateAsync(contentItem, VersionOptions.Draft); await conditionallyPublish(contentItem); return(await RedirectSelectActionResult(contentItem, onCompleteSubmitAction, returnUrl)); /*if ((!string.IsNullOrEmpty(returnUrl)) && (stayOnSamePage)) * { * return LocalRedirect(returnUrl); * } * * var adminRouteValues = (await _contentManager.PopulateAspectAsync<ContentItemMetadata>(contentItem)).AdminRouteValues; * * if (!string.IsNullOrEmpty(returnUrl)) * { * adminRouteValues.Add("returnUrl", returnUrl); * } * * return RedirectToRoute(adminRouteValues);*/ }
public async Task <IActionResult> Entry(string submission, string title, string id, string container) { var contentItem = await _contentManager.NewAsync(_id); if (!await _authorizationService.AuthorizeAsync(User, Permissions.SubmitForm, contentItem)) { return(Unauthorized()); } var subObject = JObject.Parse(submission); string guid = contentItem.ContentItemId; string subTitle = title + " " + DateTime.Now.ToUniversalTime().ToString() + " " + guid; var advFormSub = new AdvancedFormSubmissions(subObject["data"].ToString(), subObject["metadata"].ToString(), subTitle, container); var titlePart = new TitlePart(subTitle); contentItem.Content.AdvancedFormSubmissions = JToken.FromObject(advFormSub); contentItem.Content.TitlePart = JToken.FromObject(titlePart); contentItem.Content.AutoroutePart.Path = CreatePath(title, guid); if (!ModelState.IsValid) { _session.Cancel(); return(StatusCode(StatusCodes.Status406NotAcceptable)); } await _contentManager.CreateAsync(contentItem, VersionOptions.Draft); await _contentManager.PublishAsync(contentItem); return(StatusCode(StatusCodes.Status201Created)); }
private async Task <IActionResult> CreatePOST(string id, string returnUrl, bool stayOnSamePage, Func <ContentItem, Task> conditionallyPublish) { var contentItem = await _contentManager.NewAsync(id); // Set the current user as the owner to check for ownership permissions on creation contentItem.Owner = User.Identity.Name; if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, contentItem)) { return(Unauthorized()); } var model = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, true); if (!ModelState.IsValid) { _session.Cancel(); return(View(model)); } await _contentManager.CreateAsync(contentItem, VersionOptions.Draft); await conditionallyPublish(contentItem); if ((!string.IsNullOrEmpty(returnUrl)) && (!stayOnSamePage)) { return(LocalRedirect(returnUrl)); } var adminRouteValues = (await _contentManager.PopulateAspectAsync <ContentItemMetadata>(contentItem)).AdminRouteValues; if (!string.IsNullOrEmpty(returnUrl)) { adminRouteValues.Add("returnUrl", returnUrl); } return(RedirectToRoute(adminRouteValues)); }
public async Task <IActionResult> Entry(string submission, string title, string id, string container, string header, string footer, string description, string tag, string submissionId, string instructions) { ContentItem contentItem; if (!string.IsNullOrWhiteSpace(submissionId)) { contentItem = await _contentManager.GetAsync(submissionId, VersionOptions.Latest); } else { contentItem = await _contentManager.NewAsync(_id); } if (!await _authorizationService.AuthorizeAsync(User, Permissions.SubmitForm, contentItem)) { return(Unauthorized()); } var subObject = JObject.Parse(submission); string guid = contentItem.ContentItemId; string subTitle = title + " " + DateTime.Now.ToUniversalTime().ToString() + " " + guid; var advFormSub = new AdvancedFormSubmissions(subObject["data"].ToString(), subObject["metadata"].ToString(), subTitle, container, header, footer, description, tag, instructions); contentItem.Content.AdvancedFormSubmissions = JToken.FromObject(advFormSub); contentItem.DisplayText = subTitle; contentItem.Content.AutoroutePart.Path = CreatePath(title, guid); if (!ModelState.IsValid) { _session.Cancel(); return(StatusCode(StatusCodes.Status406NotAcceptable)); } if (!string.IsNullOrWhiteSpace(submissionId)) { await _contentManager.UpdateAsync(contentItem); } else { await _contentManager.CreateAsync(contentItem, VersionOptions.Draft); } await _contentManager.PublishAsync(contentItem); return(StatusCode(StatusCodes.Status201Created)); }
#pragma warning disable S1172 // some derived contexts don't have a Cancel flag, // so we handle them at the base context level by cancelling the session private void Cancel(ContentContextBase context) { _session.Cancel(); }