Beispiel #1
0
        public CreateEditTextBoxViewModel(MnTextBox textBox)
        {
            Title                = textBox.Title;
            HelpText             = textBox.HelpText;
            IsRequired           = textBox.Validations.Any(x => x.Type == ElementValidationType.Required);
            SelectedValidationId = (int)textBox.Validations.First(x => x.Type != ElementValidationType.Required).Type;

            // file ElementValidators by default validation and default value
            SeedSupportedValidation();

            // if my textBox has validation replace it validation by default ElementValidators
            foreach (var item in textBox.Validations.Where(x => x.Type != ElementValidationType.Required))
            {
                var replacedValidator = ElementValidators.Single(x => x.Type == item.Type);
                var index             = ElementValidators.IndexOf(replacedValidator);
                replacedValidator = item;
                ElementValidators.RemoveAt(index);
                ElementValidators.Insert(index, replacedValidator);
            }
        }
Beispiel #2
0
        public override object ToObject()
        {
            // create TextBox from CreateEditTextBoxViewModel
            var validation = new List <BaseElementValidator>();

            if (IsRequired)
            {
                validation.Add(new BaseElementValidator(ElementValidationType.Required)
                {
                    IsChecked = true
                });
            }

            validation.AddRange(ElementValidators.Where(x => x.IsChecked).ToList());
            var obj = new MnTextBox {
                Title = Title, HelpText = HelpText
            };

            obj.Validations.AddRange(validation);
            return(obj);
        }