You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324
  1. using System;
  2. using System.Linq;
  3. using System.Net;
  4. using System.Net.Http;
  5. using System.Web.Http.Controllers;
  6. using System.Web.Http.Filters;
  7. namespace iiie.WebApiUtils.BusinessManager.Attributes
  8. {
  9. [AttributeUsage(AttributeTargets.Method)]
  10. public class CheckModelForNullAttribute : ActionFilterAttribute
  11. {
  12. public override void OnActionExecuting(HttpActionContext actionContext)
  13. {
  14. var failed = actionContext.ActionArguments.Where(x => x.Value == null);
  15. if (failed.Any())
  16. {
  17. var failedString = string.Join(", ", failed.Select(x => x.Key));
  18. actionContext.Response = actionContext.Request.CreateErrorResponse(
  19. HttpStatusCode.BadRequest, "Missing parameters: " + failedString);
  20. }
  21. }
  22. }
  23. }