示例#1
0
        public async Task <ActionResult <PredefinedValues> > PostPredefinedValues(PredefinedValues predefinedValues)
        {
            _context.PredefinedValues.Add(predefinedValues);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPredefinedValues", new { id = predefinedValues.Id }, predefinedValues));
        }
示例#2
0
        protected override TCollection ParseValue(object value)
        {
            if (value is TCollection asT)
            {
                if (IsValueAllowed(asT))
                {
                    return(asT);
                }
                else if (Value is TCollection currentValue && IsValueAllowed(currentValue))
                {
                    return(currentValue);
                }
            }

            // if null is allowed, return null
            if (PredefinedValues.Any(x => x == null))
            {
                return(null);
            }

            // otherwise create a new instance
            var newInstance = InstantiateObject <TCollection>();

            return(newInstance);
        }
示例#3
0
        public async Task <IActionResult> PutPredefinedValues(int id, PredefinedValues predefinedValues)
        {
            if (id != predefinedValues.Id)
            {
                return(BadRequest());
            }

            _context.Entry(predefinedValues).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PredefinedValuesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#4
0
        protected override bool ParseValue(object value)
        {
            if (TryCastBool(value, out var asBool))
            {
                if (IsValueAllowed(asBool))
                {
                    return(asBool);
                }
            }

            // given value is not allowed, return the current set value instead
            if (Value is bool currentValue && IsValueAllowed(currentValue))
            {
                return(currentValue);
            }

            var predefinedValues = PredefinedValues.ToList();

            if (predefinedValues.Count == 0)
            {
                return(!IsValueAllowed(false));
            }

            return(PredefinedValues.OfType <bool>().FirstOrDefault());
        }
示例#5
0
        protected override double ParseValue(object value)
        {
            var minMax = MinMax();
            var min    = (double)minMax.Min;
            var max    = (double)minMax.Max;

            if (TryCastNumeric <double>(value, out var asDouble))
            {
                if (IsNumericValueAllowed(asDouble))
                {
                    return(asDouble);
                }
                else if (IsValueAllowed(asDouble))
                {
                    if (asDouble > max)
                    {
                        return(max);
                    }

                    if (asDouble < min)
                    {
                        return(min);
                    }
                }
            }

            // given value is not allowed, return the current set value instead
            if (Value is double currentValue && IsNumericValueAllowed(currentValue))
            {
                return(currentValue);
            }

            var predefinedValues = PredefinedValues;

            if (predefinedValues.Count == 0)
            {
                var newValue = min;
                while (!IsNumericValueAllowed(newValue) && newValue <= max)
                {
                    newValue += 1;
                }

                return(newValue);
            }

            return(PredefinedValues.OfType <double>().FirstOrDefault());
        }
示例#6
0
        protected override string ParseValue(object value)
        {
            var asString = value as string ?? value?.ToString();

            if (IsValueAllowed(asString))
            {
                return(asString);
            }

            // given value is not allowed, return the current set value instead
            var currentValue = Value as string ?? Value?.ToString();

            // if current value is also null, try to use the first PredefinedValue
            var allowedValues = PredefinedValues.OfType <string>();

            return(IsValueAllowed(currentValue) ? currentValue : allowedValues.FirstOrDefault());
        }
        protected override T ParseValue(object value)
        {
            if (value is T asT)
            {
                if (IsValueAllowed(asT))
                {
                    if (!ReferenceEquals(Value, asT) || !SubEditables.Any())
                    {
                        CreateSubEditables(asT);
                    }
                    return(asT);
                }
                else if (Value is T currentValue && IsValueAllowed(currentValue))
                {
                    return(currentValue);
                }
            }

            // if null is allowed, return null
            var isNullAllowed = PredefinedValues.Any(x => x == null);

            if (isNullAllowed)
            {
                return(null);
            }

            var predefinedValuesOfT = PredefinedValues.OfType <T>().ToList();

            if (predefinedValuesOfT.Any())
            {
                return(predefinedValuesOfT.First());
            }

            // otherwise create a new instance
            var newInstance = (T)InstantiateObjectOfSpecificType(GetPredefinedType());

            CreateSubEditables(newInstance);
            return(newInstance);
        }
示例#8
0
        protected override KeyValuePair <TKey, TValue> ParseValue(object value)
        {
            if (value is KeyValuePair <TKey, TValue> asKeyValuePair && IsValueAllowed(asKeyValuePair))
            {
                return(asKeyValuePair);
            }

            // given value is not allowed, return the current set value instead
            if (Value is KeyValuePair <TKey, TValue> currentValue && IsValueAllowed(currentValue))
            {
                return(currentValue);
            }

            var predefinedValues = PredefinedValues.ToList();

            if (predefinedValues.Count == 0)
            {
                return(new KeyValuePair <TKey, TValue>());
            }

            return(PredefinedValues.OfType <KeyValuePair <TKey, TValue> >().FirstOrDefault());
        }
		public PredefinedValueAttribute(PredefinedValues val)
		{
			Value = val;
		}
示例#10
0
 private object PredefinedSetValidate(string value)
 {
     IsValid = PredefinedValues.Contains(value.Trim().ToUpper());
     return(IsValid ? value : null);
 }
示例#11
0
 internal SpecialRegister(PredefinedValues val)
 {
     Value = val;
 }
示例#12
0
		internal SpecialRegister(PredefinedValues val)
		{
			Value = val;
		}
 public PredefinedValueAttribute(PredefinedValues val)
 {
     Value = val;
 }