示例#1
0
        public static IHtmlContent NumberPickerFor <TModel, TValue>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression)
        {
            IHtmlContent respVal = new HtmlString("");

            if (expression.Body is MemberExpression memEx)
            {
                NumericalRangeAttribute range = memEx.Member.GetCustomAttributes(typeof(NumericalRangeAttribute), false)
                                                .Cast <NumericalRangeAttribute>().Single();
                string id   = html.IdFor(expression);
                string name = html.NameFor(expression);
                respVal = new HtmlString($@"<number-input v-model='{name}' id='{id}' name='{name}' :step='{range.Step}' :min='{range.Min}' :max='{range.Max}' class='number_picker' inline controls></number-input>");
            }
            return(respVal);
        }
示例#2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> respVal = new List <ValidationResult>();

            if (Type == PpeTypes.Other && Selected && String.IsNullOrWhiteSpace(PpeTypeOther))
            {
                respVal.Add(new ValidationResult("Please add <b>PPE Type Other</b> to describe the PPE Type when choosing <b>\"Other...\"</b>",
                                                 new List <string> {
                    $"{PpeTypeOther}"
                }));
            }
            if (Type == PpeTypes.FFP1RespiratorMasks && Selected)
            {
                if (DailyShortage == null)
                {
                    respVal.Add(new ValidationResult("Please add <b>Daily FFP1 Shortage</b>",
                                                     new List <string> {
                        $"{nameof(DailyShortage)}"
                    }));
                }
                else
                {
                    MemberInfo m = validationContext.ObjectType.GetMember(nameof(DailyShortage))[0];
                    NumericalRangeAttribute numRange         = m.GetCustomAttributes(typeof(NumericalRangeAttribute), false).Cast <NumericalRangeAttribute>().Single();
                    DisplayAttribute        displayAttribute = m.GetCustomAttributes(typeof(DisplayAttribute), false).Cast <DisplayAttribute>().Single();
                    if (!(numRange.Min <= DailyShortage.Value && DailyShortage.Value <= numRange.Max))
                    {
                        respVal.Add(new ValidationResult(String.Format(Settings.ValMsgs.NumRange, displayAttribute.Name, numRange.Min, numRange.Max),
                                                         new List <string> {
                            $"{nameof(DailyShortage)}"
                        }));
                    }
                }
                if (String.IsNullOrWhiteSpace(DailyShortageForWhom))
                {
                    respVal.Add(new ValidationResult("Please add <b>Daily FFP1 Shortage Details</b>",
                                                     new List <string> {
                        $"{nameof(DailyShortageForWhom)}"
                    }));
                }
            }
            return(respVal);
        }