Streamlines validation response handling in controllers

This makes validation response handling more inline with aspnetcore patterns.
This commit is contained in:
Shannon
2021-06-25 10:29:18 -06:00
parent 2e3239ce6b
commit 055dacbb0e
25 changed files with 335 additions and 207 deletions

View File

@@ -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());
}
}