/// <summary> /// Creates a new <see cref="IResponse"/> that represents a failed /// response for a bad request due to model state validation errors. /// </summary> /// <param name="factory"><see cref="IResponseFactory"/></param> /// <param name="modelState">The <see cref="ModelStateDictionary"/> which contains the model validation errors.</param> /// <returns><see cref="IResponse"/></returns> public static IResponse BadRequest(this IResponseFactory factory, ModelStateDictionary modelState) { if (modelState == null) { throw new ArgumentNullException(nameof(modelState)); } if (modelState.IsValid) { throw new InvalidOperationException(); } // the SerializableError for a ModelStateDictionary is really a IDictionary<string, string[]> var errors = new SerializableError(modelState) .ToDictionary(pair => pair.Key, pair => (string[])pair.Value); return(factory.BadRequest(errors)); }
/// <summary> /// Request is bad or rejected /// </summary> /// <param name="message">The message.</param> /// <returns>Response.</returns> public static Response BadRequest(string message = null) { return(Default.BadRequest(message)); }