示例#1
0
        /// <inheritdoc />
        public Task Authorize(AuthorizationContext context)
        {
            bool found = false;

            if (context.User != null)
            {
                if (AllowedValues == null || !AllowedValues.Any())
                {
                    found = context.User.Claims.Any(
                        claim => string.Equals(claim.Type, ClaimType, StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    found = context.User.Claims.Any(
                        claim => string.Equals(claim.Type, ClaimType, StringComparison.OrdinalIgnoreCase) &&
                        AllowedValues.Contains(claim.Value, StringComparer.Ordinal));
                }
            }

            if (!found)
            {
                if (AllowedValues != null && AllowedValues.Any())
                {
                    string values = string.Join(", ", DisplayValues ?? AllowedValues);
                    context.ReportError($"Required claim '{ClaimType}' with any value of '{values}' is not present.");
                }
                else
                {
                    context.ReportError($"Required claim '{ClaimType}' is not present.");
                }
            }

            return(Task.CompletedTask);
        }
        private string BuildButton(WorkItemStatus statusValue)
        {
            var classes = new List <string>()
            {
                "ui", "button"
            };

            var isCurrentValue = false;

            if (CurrentValue.HasValue)
            {
                if (CurrentValue == statusValue)
                {
                    classes.Add("active");
                    isCurrentValue = true;
                }
            }
            else
            {
                if (statusValue == DefaultValue)
                {
                    classes.Add("active");
                    isCurrentValue = true;
                }
            }

            if (AllowedValues != null && !AllowedValues.Contains(statusValue) && !isCurrentValue)
            {
                classes.Add("disabled");
            }

            var buttonTemplate = $"<button type=\"button\" data-status=\"{statusValue}\" class=\"{string.Join(" ", classes)}\">{statusValue.GetDisplayName()}</button>";

            return(buttonTemplate);
        }
示例#3
0
        public string this[string columnName]
        {
            get
            {
                string msg = null;

                if (string.IsNullOrEmpty(To) || string.IsNullOrWhiteSpace(To))
                {
                    msg = "соответствие не может быть пустым";
                }
                else if (AllowedValues.Count > 0 && !AllowedValues.Contains(To))
                {
                    msg = "введено нестандартное значение";
                }
                return(msg);
            }
        }
 public override bool IsValid(object?value) => AllowedValues.Contains(value?.ToString());