Streamlines validation response handling in controllers
This makes validation response handling more inline with aspnetcore patterns.
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
using Umbraco.Cms.Web.BackOffice.Filters;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
using Umbraco.Cms.Web.BackOffice.Filters;
|
||||
using Umbraco.Cms.Web.Common.ActionsResults;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
{
|
||||
@@ -11,5 +15,30 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
[AppendCurrentEventMessages]
|
||||
public abstract class BackOfficeNotificationsController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
/// <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)
|
||||
{
|
||||
var notificationModel = new SimpleNotificationModel
|
||||
{
|
||||
Message = errorMessage
|
||||
};
|
||||
notificationModel.AddErrorNotification(errorMessage, string.Empty);
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user