Ejemplo n.º 1
0
        private void DeleteFormField(Guid formId)
        {
            var formFields = formFieldRepository.FindByFormId(formId);

            foreach (var formField in formFields)
            {
                var options = optionRepository.FindByFormFieldId(formField.Id);
                foreach (var option in options)
                {
                    entityRepository.DeleteOnSave(option);
                }
                entityRepository.DeleteOnSave(formField);
            }
        }
Ejemplo n.º 2
0
        private void CreateOption(Guid formFieldId, FormFieldModel formFieldModel)
        {
            var options = optionRepository.FindByFormFieldId(formFieldId);

            foreach (var option in options)
            {
                formFieldModel.Options.Add(new OptionModel()
                {
                    Checked = option.Checked,
                    Content = option.Content,
                    Value   = option.Value
                });
            }
        }
Ejemplo n.º 3
0
        private FormViewModel BuildFormModel(Guid?formId, bool forEdit)
        {
            var form = formRepository.Find(formId);

            if (form == null)
            {
                return(null);
            }
            var formModel = new FormViewModel()
            {
                Body = new FormBodyViewModel()
                {
                    Description = form.Description,
                    Title       = form.Title
                }
            };

            var formFields = formFieldRepository.FindByFormId(form.Id);

            foreach (var formField in formFields)
            {
                var type = formFieldTypeRepository.FindByTypeId(formField.TypeId);
                formModel.Body.FormFields.Add(new FormFieldViewModel()
                {
                    Id    = formField.Id,
                    Title = formField.Title,
                    Type  = forEdit ? type.Name : type.DisplayName,
                    Value = formField.Value
                });

                var validation = formFieldRuleRepository.FindByFormFieldId(formField.Id);
                foreach (var v in validation)
                {
                    var  validationType = validationRuleRepository.Find(v.ValidationRuleId);
                    Guid valueId        = v.ValueId ?? Guid.Empty;
                    var  value          = string.Empty;
                    if (valueId != Guid.Empty)
                    {
                        var valueType = v.ValueType;
                        switch (valueType)
                        {
                        case DataLayer.Entities.ValueType.DateTime:
                            value = validationRuleValueRepository.FindDateTime(valueId).Value.ToShortDateString();
                            break;

                        case DataLayer.Entities.ValueType.Number:
                            value = validationRuleValueRepository.FindDouble(valueId).Value.ToString();
                            break;

                        case DataLayer.Entities.ValueType.String:
                            value = validationRuleValueRepository.FindString(valueId).Value;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(valueType), valueType, null);
                        }
                    }
                    formModel.Body.FormFields.Last().Validation.Add(new ValidationViewModel()
                    {
                        Type  = forEdit ? validationType.Name : validationType.DisplayName,
                        Value = value
                    });
                }
                ;

                var options = optionRepository.FindByFormFieldId(formField.Id);
                foreach (var option in options)
                {
                    formModel.Body.FormFields.Last().Options.Add(new OptionViewModel()
                    {
                        Checked = option.Checked,
                        Content = option.Content,
                        Value   = option.Value
                    });
                }
            }

            return(formModel);
        }