Skip to content

Commit

Permalink
Merge pull request #252 from Lombiq/issue/OFFI-19
Browse files Browse the repository at this point in the history
OFFI-19: Adding content validation extension
  • Loading branch information
sarahelsaig authored Apr 9, 2024
2 parents 48d945e + a71599a commit efd2b14
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using OrchardCore.ContentManagement.Handlers;
using System.Linq;

namespace Lombiq.HelpfulLibraries.OrchardCore.Validation;

public static class ContentValidateResultExtensions
{
public static void AddValidationErrorsToModelState(this ContentValidateResult result, ModelStateDictionary modelState)
{
foreach (var error in result.Errors)
{
if (error.MemberNames.Any())
{
foreach (var memberName in error.MemberNames)
{
modelState.AddModelError(memberName, error.ErrorMessage);
}
}
else
{
modelState.AddModelError(string.Empty, error.ErrorMessage);
}
}
}
}

0 comments on commit efd2b14

Please sign in to comment.