| | | 1 | | using Microsoft.AspNetCore.Mvc; |
| | | 2 | | using Microsoft.AspNetCore.Mvc.Filters; |
| | | 3 | | using System; |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Linq; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | |
| | | 8 | | namespace SVETA.Api.Controllers |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Отдает ошибку валидации моделей контроллера в стандартном едином виде |
| | | 12 | | /// </summary> |
| | | 13 | | public class ValidateModelAttribute : IActionFilter |
| | | 14 | | { |
| | | 15 | | public void OnActionExecuted(ActionExecutedContext context) |
| | 0 | 16 | | { |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | public void OnActionExecuting(ActionExecutingContext context) |
| | 0 | 20 | | { |
| | 0 | 21 | | if (!context.ModelState.IsValid) |
| | 0 | 22 | | { |
| | 0 | 23 | | context.Result = new ValidationFailedResult(context.ModelState); |
| | 0 | 24 | | } |
| | 0 | 25 | | } |
| | | 26 | | } |
| | | 27 | | } |