2021-06-25 10:29:18 -06:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-06-25 10:42:09 -06:00
|
|
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
2021-06-25 10:29:18 -06:00
|
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
2021-06-25 10:42:09 -06:00
|
|
|
using Umbraco.Cms.Web.BackOffice.ActionResults;
|
2021-06-25 10:29:18 -06:00
|
|
|
using Umbraco.Cms.Web.BackOffice.Filters;
|
|
|
|
|
using Umbraco.Cms.Web.Common.ActionsResults;
|
|
|
|
|
using Umbraco.Extensions;
|
2020-05-22 07:26:46 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Web.BackOffice.Controllers
|
2020-05-22 07:26:46 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An abstract controller that automatically checks if any request is a non-GET and if the
|
|
|
|
|
/// resulting message is INotificationModel in which case it will append any Event Messages
|
|
|
|
|
/// currently in the request.
|
|
|
|
|
/// </summary>
|
2020-06-18 14:40:30 +02:00
|
|
|
[PrefixlessBodyModelValidator]
|
2020-08-04 12:27:21 +10:00
|
|
|
[AppendCurrentEventMessages]
|
2020-05-22 07:26:46 +02:00
|
|
|
public abstract class BackOfficeNotificationsController : UmbracoAuthorizedJsonController
|
|
|
|
|
{
|
2021-06-25 10:42:09 -06:00
|
|
|
/// <summary>
|
|
|
|
|
/// returns a 200 OK response with a notification message
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected OkObjectResult Ok(string message)
|
|
|
|
|
{
|
|
|
|
|
var notificationModel = new SimpleNotificationModel
|
|
|
|
|
{
|
|
|
|
|
Message = message
|
|
|
|
|
};
|
|
|
|
|
notificationModel.AddSuccessNotification(message, string.Empty);
|
|
|
|
|
|
|
|
|
|
return new OkObjectResult(notificationModel);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-25 10:29:18 -06:00
|
|
|
/// <summary>
|
|
|
|
|
/// Overridden to ensure that the error message is an error notification message
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="errorMessage"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected override ActionResult ValidationProblem(string errorMessage)
|
2021-06-25 10:42:09 -06:00
|
|
|
=> ValidationProblem(errorMessage, string.Empty);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a notofication validation problem with a header and message
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="errorHeader"></param>
|
|
|
|
|
/// <param name="errorMessage"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected ActionResult ValidationProblem(string errorHeader, string errorMessage)
|
2021-06-25 10:29:18 -06:00
|
|
|
{
|
|
|
|
|
var notificationModel = new SimpleNotificationModel
|
|
|
|
|
{
|
|
|
|
|
Message = errorMessage
|
|
|
|
|
};
|
2021-06-25 10:42:09 -06:00
|
|
|
notificationModel.AddErrorNotification(errorHeader, errorMessage);
|
2021-06-25 10:29:18 -06:00
|
|
|
return new ValidationErrorResult(notificationModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Overridden to ensure that all queued notifications are sent to the back office
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
public override ActionResult ValidationProblem()
|
|
|
|
|
// returning an object of INotificationModel will ensure that any pending
|
|
|
|
|
// notification messages are added to the response.
|
|
|
|
|
=> new ValidationErrorResult(new SimpleNotificationModel());
|
|
|
|
|
|
2020-05-22 07:26:46 +02:00
|
|
|
}
|
|
|
|
|
}
|