private async Task <IActionResult> EditPOST(string contentItemId, string returnUrl, CompleteActionOutCome onCompleteActionOutCome, Func <ContentItem, Task> conditionallyPublish) { var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.DraftRequired); if (contentItem == null) { return(NotFound()); } if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, contentItem)) { return(Forbid()); } //string previousRoute = null; //if (contentItem.Has<IAliasAspect>() && // !string.IsNullOrWhiteSpace(returnUrl) // && Request.IsLocalUrl(returnUrl) // // only if the original returnUrl is the content itself // && String.Equals(returnUrl, Url.ItemDisplayUrl(contentItem), StringComparison.OrdinalIgnoreCase) // ) //{ // previousRoute = contentItem.As<IAliasAspect>().Path; //} var model = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false); if (!ModelState.IsValid) { _session.Cancel(); //return View("Edit", model); // return Json("ModelState is invalid"); return(LocalRedirect(returnUrl)); } // The content item needs to be marked as saved in case the drivers or the handlers have // executed some query which would flush the saved entities inside the above UpdateEditorAsync. _session.Save(contentItem); await conditionallyPublish(contentItem); return(await RedirectSelectActionResult(contentItem, onCompleteActionOutCome, returnUrl)); /*if (returnUrl == null) * { * return RedirectToAction("Edit", new RouteValueDictionary { { "ContentItemId", contentItem.ContentItemId } }); * } * else if (stayOnSamePage) * { * return RedirectToAction("Edit", new RouteValueDictionary { { "ContentItemId", contentItem.ContentItemId }, { "returnUrl", returnUrl } }); * } * else * { * return LocalRedirect(returnUrl); * }*/ }
private async Task <IActionResult> RedirectSelectActionResult(ContentItem contentItem, CompleteActionOutCome OnCompleteActionOutCome, string returnUrl) { var cim = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(contentItem); switch (OnCompleteActionOutCome) { case CompleteActionOutCome.Admin: // if (!string.IsNullOrEmpty(returnUrl)) // { // cim.AdminRouteValues.Add("returnUrl", returnUrl); // } return(RedirectToRoute(cim.AdminRouteValues)); case CompleteActionOutCome.Display: return(RedirectToRoute(cim.DisplayRouteValues)); case CompleteActionOutCome.Edit: return(RedirectToRoute(cim.EditorRouteValues)); case CompleteActionOutCome.Create: return(RedirectToRoute(cim.CreateRouteValues)); case CompleteActionOutCome.StayOnSamePage: return(LocalRedirect(returnUrl)); default: throw new ArgumentOutOfRangeException(nameof(CompleteActionOutCome), OnCompleteActionOutCome, null); } }
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);*/ }