Example #1
0
        public void AddChoice(Choice choice)
        {
            if (Choices.Any(x => x.Name == choice.Name))
            {
                return;
            }

            Choices.Add(choice);
            OnChoicesUpdated();
        }
Example #2
0
 public bool ExistsFeatureById(int id)
 { // Verifica se existe um certo Feature dentre os Features do personagem
     if (Virtues.Any(virtue => virtue.Id == id) || Choices.Any(virtue => virtue.Id == id))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #3
0
        public async Task GetChoiceAsync()
        {
            if (Choices?.Any() != true)
            {
                return;
            }

            CurrentChoice = _choiceService.MakeChoice(Choices);
            Console.WriteLine($"Made choice: {CurrentChoice}");

            NotifyStateChanged();

            await Task.CompletedTask;
        }
Example #4
0
        public ChoiceListAttribute(object[] choices, string[] displayNames = null)
        {
            Choices      = choices ?? throw new ArgumentNullException(nameof(choices));
            DisplayNames = displayNames ?? choices.Select(e => e.ToString()).ToArray();

            if (Choices.Any(e => string.IsNullOrEmpty(e?.ToString())))
            {
                // Programmer error
                throw new ArgumentException($"One of the choices cannot be blank");
            }

            if (Choices.Length != DisplayNames.Length)
            {
                // Programmer error
                throw new ArgumentException($"There are {Choices.Length} choices and {DisplayNames.Length} display names");
            }

            if (Choices.Length == 0)
            {
                // Programmer error
                throw new ArgumentException("At least one choice is required");
            }
        }
Example #5
0
        public bool Validate(out string error)
        {
            error = string.Empty;

            if (string.IsNullOrWhiteSpace(Text))
            {
                error = "Please specify text for the poll";
                return(false);
            }

            if (Text.Length > MaxTextLength)
            {
                error = string.Format("Poll text must be {0} characters or less", MaxTextLength);
                return(false);
            }

            if (Choices.Count < MinChoices)
            {
                error = string.Format("Poll must have at least {0} choies", MinChoices);
                return(false);
            }

            if (Choices.Count > MaxChoices)
            {
                error = string.Format("Polls must not have more than {0} choies", MaxChoices);
                return(false);
            }

            if (Choices.Any(c => c.Text.Length > MaxChoiceTextLength))
            {
                error = string.Format("All choices must be {0} characters or less", MaxChoiceTextLength);
                return(false);
            }

            return(true);
        }
Example #6
0
        /// <summary>
        /// Performs value validation.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private object ValidateValue(object value)
        {
            Exception ex = null;

            ValidationException = null;
            object temp = _value;

            // Performs type and length validation.
            if (OutField != null)
            {
                if (OutField.Domain != null)
                {
                    if (value is string)
                    {
                        foreach (var item in OutField.Domain)
                        {
                            if (item.Value == value as string)
                            {
                                temp = item;
                                break;
                            }
                        }
                    }
                    else
                    {
                        temp = value;
                    }
                }
                else
                {
                    temp = FieldValue.ValidateValue(OutField, value, out ex);
                    if (ex != null && (value == null || string.IsNullOrWhiteSpace(value.ToString())))
                    {
                        // Special handling of validation errors due to null or empty input - set value to null and
                        // only set ValidationException if empty values are not allowed
                        temp = null;
                        if (!AllowEmptyValues)
                        {
                            ValidationException = new Exception(Strings.EmptyEntryError);
                        }
                    }
                    else if (ex != null)
                    {
                        ValidationException = new Exception(Strings.InvalidValue);
                    }
                }
            }

            if (ex == null)
            {
                if (Choices != null)
                {
                    // Checks for duplicate entries.
                    if (Choices.Any(c => c != this && FieldValueEqualityComparer.EqualObject(c.ValueInCorrectType, temp)))
                    {
                        ValidationException = new ArgumentException(Strings.DuplicateError);
                    }
                }
            }

            return(temp);
        }
Example #7
0
 /// <summary>
 /// Resets ChoiceValues to default settings.
 /// </summary>
 public void Reset(bool useDefaultValue)
 {
     SelectedChoice = Choices != null && Choices.Any() ? Choices.FirstOrDefault() : null;
     CurrentValue   = useDefaultValue ? new FieldValue(DefaultValue) : new FieldValue(SelectedChoice);
 }