blob: 643c99ac8ad3325f262dad9d0ac5bedbd77025df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
using Microsoft.AspNetCore.Mvc;
using System.Text;
using Timeline.Models.Http;
namespace Timeline.Helpers
{
public static class InvalidModelResponseFactory
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods")]
public static IActionResult Factory(ActionContext context)
{
var modelState = context.ModelState;
var messageBuilder = new StringBuilder();
foreach (var model in modelState)
foreach (var error in model.Value.Errors)
{
messageBuilder.Append(model.Key);
messageBuilder.Append(" : ");
messageBuilder.AppendLine(error.ErrorMessage);
}
return new BadRequestObjectResult(CommonResponse.InvalidModel(messageBuilder.ToString()));
}
}
}
|