/// <inheritdoc />
        public override void OnActionExecuting(ActionExecutingContext actionContext)
        {
            if (_names.Count == 0)
            {
                return;
            }

            KeyValuePair <string, StringValues>[] parameters =
                actionContext.HttpContext
                .Request
                .Query
                .Where(x => _names.Contains(x.Key))
                .ToArray();

            bool check0 =
                _names.All(x => parameters.Select(y => y.Key).Contains(x));

            bool check1 =
                parameters.All(x => x.Value
                               .SelectMany(y => y.Split(','))
                               .All(y => !string.IsNullOrEmpty(y) &&
                                    !string.IsNullOrWhiteSpace(y)));

            if (check0 && check1)
            {
                return;
            }

            actionContext.Result =
                new ContentResult
            {
                StatusCode  = (int)HttpStatusCode.BadRequest,
                ContentType = "text/plain",
                Content     =
                    _names.Count == 1
                            ? $"Parameter '{_names.Single()}' is required."
                            : $"Parameters [{string.Join(", ", _names)}] are required."
            };
        }
예제 #2
0
 protected override bool IsSatisfied(StringValues values, NumberStyles numberStyles, CultureInfo cultureInfo)
 {
     return(values.All(value => (value == "" && Optional) || ValidationRegex.IsMatch(value)));
 }
예제 #3
0
 /// <summary>
 /// Returns <c>true</c> if the X-Client-ID HTTP header contains a non empty value, otherwise <c>false</c>.
 /// </summary>
 /// <param name="headerValues">The header values.</param>
 /// <returns><c>true</c> if the X-Client-ID HTTP header values are valid; otherwise, <c>false</c>.</returns>
 public override bool IsValid(StringValues headerValues) =>
 !StringValues.IsNullOrEmpty(headerValues) && headerValues.All(x => !string.IsNullOrWhiteSpace(x));
예제 #4
0
 protected override bool IsSatisfied(StringValues values, NumberStyles numberStyles, CultureInfo cultureInfo)
 {
     return(values.All(value => (value == "" && Optional) || SatisfiesPredicate(value)));
 }
예제 #5
0
 protected override bool IsSatisfied(StringValues values, NumberStyles numberStyles, CultureInfo cultureInfo)
 {
     return(values.All(value => (value == "" && Optional) || double.TryParse(value, numberStyles, cultureInfo, out _)));
 }