Example #1
0
        public void Deve_Vincular_Um_Formulario_A_Um_Componente()
        {
            var pageComponent = new PageComponent("Novo componente");

            Assert.IsTrue(pageComponent.Valid);
            Assert.AreEqual(pageComponent.EntityStatus, EntityStatus.Activated);


            var formPageComponent = new FormPageComponent(pageComponent.Id, _customForm.Id, _tenant.Id);

            Assert.IsTrue(formPageComponent.Valid);
            Assert.AreEqual(formPageComponent.EntityStatus, EntityStatus.Activated);
            Assert.AreEqual(_tenant.Id, formPageComponent.TenantId);
            Assert.AreEqual(pageComponent.Id, formPageComponent.PageComponentId);
        }
Example #2
0
        public ICommandResult Handle(CreateCustomFormRequest command)
        {
            if (!command.IsValid())
            {
                return(new CommandResult(false, "Request inválida", command));
            }

            var customForm = new CustomForm(command.Name, _tenant.Id);

            AddNotifications(customForm.Notifications);

            if (command.Fields != null)
            {
                foreach (var fieldCommand in command.Fields)
                {
                    var customField = new CustomField(fieldCommand.Name, fieldCommand?.Description, fieldCommand.Type, customForm.Id, fieldCommand.Mandatory, _tenant.Id);

                    AddNotifications(customField.Notifications);

                    if (customField.HasOptions())
                    {
                        if (fieldCommand.Options == null || fieldCommand.Options.Count == 0)
                        {
                            AddNotification("Type", $"Campo {fieldCommand.Name} deve conter opções.");
                        }
                    }

                    if (fieldCommand.Options != null)
                    {
                        foreach (var optionCommand in fieldCommand.Options)
                        {
                            var customFieldOption =
                                new CustomFieldOption(optionCommand.Name, customField.Id, _tenant.Id);

                            AddNotifications(customFieldOption.Notifications);

                            customField.AddOption(customFieldOption);
                        }
                    }

                    customForm.AddField(customField);
                }
            }
            else
            {
                AddNotification("Fields", "Os campos do formulário não foram inseridos.");
            }

            if (Valid)
            {
                _customFormRepository.Save(customForm);

                if (command.PageComponentId.HasValue)
                {
                    var formPageComponent = new FormPageComponent(command.PageComponentId.Value, customForm.Id, _tenant.Id);

                    AddNotifications(formPageComponent.Notifications);

                    _formPageComponentRepository.Save(formPageComponent);
                }
            }

            if (Valid)
            {
                return(new CommandResult(true, "Formulário cadastrado com sucesso", new { Id = customForm.Id, Name = customForm.Name }));
            }
            else
            {
                return(new CommandResult(false, "Erro ao cadastrar formulário", Notifications));
            }
        }
Example #3
0
 public void Update(FormPageComponent entity)
 {
     Context.Entry(entity).State = EntityState.Modified;
 }
Example #4
0
 public void Save(FormPageComponent entity)
 {
     Context.FormPageComponents.Add(entity);
 }