23 lines
627 B
C#
23 lines
627 B
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using isn;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
namespace isnd.Helpers
|
|
{
|
|
public static class ApiHelpers
|
|
{
|
|
|
|
static public APIKO CreateAPIKO(this Controller controller, string context)
|
|
{
|
|
Dictionary<string,string[]> errors = new();
|
|
|
|
foreach (var elt in controller.ModelState)
|
|
{
|
|
errors[elt.Key] = elt.Value.Errors.Select( e => e.ErrorMessage).ToArray();
|
|
}
|
|
return new APIKO{ Context = context, Errors = errors };
|
|
}
|
|
}
|
|
} |