Exemplo n.º 1
0
        public ActionResult DiscardDraft(int id, string returnUrl)
        {
            var contentItem = _contentManager.Get(id, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(HttpNotFound());
            }

            if (!contentItem.TypeDefinition.Settings.GetModel <ContentTypeSettings>().Draftable ||
                !contentItem.HasPublished() ||
                contentItem.IsPublished())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!Services.Authorizer.Authorize(Permissions.DeleteContent, contentItem, T("You do not have permission to delete content (or discard draft content).")))
            {
                return(new HttpUnauthorizedResult());
            }

            _contentManager.DiscardDraft(contentItem);

            Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName)
                ? T("The draft content has been removed.")
                : T("The draft {0} has been removed.", contentItem.TypeDefinition.DisplayName));

            return(this.RedirectLocal(returnUrl, () => RedirectToAction("List")));
        }