Ejemplo n.º 1
0
        public static void CanReorder(ReorderFields command, Schema schema)
        {
            Guard.NotNull(command, nameof(command));

            IArrayField?arrayField = null;

            if (command.ParentFieldId.HasValue)
            {
                arrayField = GuardHelper.GetArrayFieldOrThrow(schema, command.ParentFieldId.Value, false);
            }

            Validate.It(e =>
            {
                if (command.FieldIds == null)
                {
                    e(Not.Defined(nameof(command.FieldIds)), nameof(command.FieldIds));
                }

                if (arrayField == null)
                {
                    ValidateFieldIds(command, schema.FieldsById, e);
                }
                else
                {
                    ValidateFieldIds(command, arrayField.FieldsById, e);
                }
            });
        }
Ejemplo n.º 2
0
        public static void CanReorder(Schema schema, ReorderFields command)
        {
            Guard.NotNull(command, nameof(command));

            IArrayField arrayField = null;

            if (command.ParentFieldId.HasValue)
            {
                arrayField = GuardHelper.GetArrayFieldOrThrow(schema, command.ParentFieldId.Value, false);
            }

            Validate.It(() => "Cannot reorder schema fields.", error =>
            {
                if (command.FieldIds == null)
                {
                    error("Field ids is required.", nameof(command.FieldIds));
                }

                if (arrayField == null)
                {
                    ValidateFieldIds(error, command, schema.FieldsById);
                }
                else
                {
                    ValidateFieldIds(error, command, arrayField.FieldsById);
                }
            });
        }
Ejemplo n.º 3
0
        public static void CanUpdate(Schema schema, UpdateField command)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId);

            if (field.IsLocked)
            {
                throw new DomainException("Schema field is already locked.");
            }

            Validate.It(() => "Cannot update field.", e =>
            {
                if (command.Properties == null)
                {
                    e("Properties is required.", nameof(command.Properties));
                }
                else
                {
                    var errors = FieldPropertiesValidator.Validate(command.Properties);

                    errors.Foreach(x => x.WithPrefix(nameof(command.Properties)).AddTo(e));
                }
            });
        }
Ejemplo n.º 4
0
        public static void CanHide(HideField command, Schema schema)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (!field.IsForApi(true))
            {
                throw new DomainException("UI field cannot be hidden.");
            }
        }
Ejemplo n.º 5
0
        public static void CanDelete(Schema schema, DeleteField command)
        {
            Guard.NotNull(command);

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (field.IsLocked)
            {
                throw new DomainException("Schema field is locked.");
            }
        }
Ejemplo n.º 6
0
        public static void CanDisable(DisableField command, Schema schema)
        {
            Guard.NotNull(command);

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (!field.IsForApi(true))
            {
                throw new DomainException("UI field cannot be diabled.");
            }
        }
Ejemplo n.º 7
0
        public static void CanLock(Schema schema, LockField command)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (field.IsLocked)
            {
                throw new DomainException("Schema field is already locked.");
            }
        }
Ejemplo n.º 8
0
        public static void CanEnable(Schema schema, EnableField command)
        {
            Guard.NotNull(command);

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (!field.IsDisabled)
            {
                throw new DomainException("Schema field is already enabled.");
            }
        }
Ejemplo n.º 9
0
        public static void CanShow(Schema schema, ShowField command)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (!field.IsHidden)
            {
                throw new DomainException("Schema field is already visible.");
            }
        }
Ejemplo n.º 10
0
        public static void CanDisable(DisableField command, Schema schema)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (!field.IsForApi(true))
            {
                throw new DomainException(T.Get("schemas.uiFieldCannotBeDisabled"));
            }
        }
Ejemplo n.º 11
0
        public static void CanHide(Schema schema, HideField command)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId);

            if (field.IsLocked)
            {
                throw new DomainException("Schema field is locked.");
            }

            if (field.IsHidden)
            {
                throw new DomainException("Schema field is already hidden.");
            }
        }
Ejemplo n.º 12
0
        public static void CanHide(Schema schema, HideField command)
        {
            Guard.NotNull(command);

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (field.IsHidden)
            {
                throw new DomainException("Schema field is already hidden.");
            }

            if (!field.IsForApi())
            {
                throw new DomainException("UI field cannot be hidden.");
            }
        }
Ejemplo n.º 13
0
        public static void CanDisable(Schema schema, DisableField command)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId);

            if (field.IsDisabled)
            {
                throw new DomainException("Schema field is already disabled.");
            }

            if (!field.IsForApi())
            {
                throw new DomainException("UI field cannot be disabled.");
            }
        }
Ejemplo n.º 14
0
        public static void CanAdd(Schema schema, AddField command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot add a new field.", e =>
            {
                if (!command.Name.IsPropertyName())
                {
                    e("Name must be a valid javascript property name.", nameof(command.Name));
                }

                if (command.Properties == null)
                {
                    e(Not.Defined("Properties"), nameof(command.Properties));
                }
                else
                {
                    var errors = FieldPropertiesValidator.Validate(command.Properties);

                    errors.Foreach(x => x.WithPrefix(nameof(command.Properties)).AddTo(e));
                }

                if (command.ParentFieldId.HasValue)
                {
                    var arrayField = GuardHelper.GetArrayFieldOrThrow(schema, command.ParentFieldId.Value, false);

                    if (arrayField.FieldsByName.ContainsKey(command.Name))
                    {
                        e("A field with the same name already exists.");
                    }
                }
                else
                {
                    if (command.ParentFieldId == null && !command.Partitioning.IsValidPartitioning())
                    {
                        e(Not.Valid("Partitioning"), nameof(command.Partitioning));
                    }

                    if (schema.FieldsByName.ContainsKey(command.Name))
                    {
                        e("A field with the same name already exists.");
                    }
                }
            });
        }
Ejemplo n.º 15
0
        public static void CanAdd(AddField command, Schema schema)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(e =>
            {
                if (!command.Name.IsPropertyName())
                {
                    e(Not.ValidJavascriptName(nameof(command.Name)), nameof(command.Name));
                }

                if (command.Properties == null)
                {
                    e(Not.Defined(nameof(command.Properties)), nameof(command.Properties));
                }
                else
                {
                    var errors = FieldPropertiesValidator.Validate(command.Properties);

                    errors.Foreach((x, _) => x.WithPrefix(nameof(command.Properties)).AddTo(e));
                }

                if (command.ParentFieldId.HasValue)
                {
                    var arrayField = GuardHelper.GetArrayFieldOrThrow(schema, command.ParentFieldId.Value, false);

                    if (arrayField.FieldsByName.ContainsKey(command.Name))
                    {
                        e(T.Get("schemas.fieldNameAlreadyExists"));
                    }
                }
                else
                {
                    if (command.ParentFieldId == null && !command.Partitioning.IsValidPartitioning())
                    {
                        e(Not.Valid("Partitioning"), nameof(command.Partitioning));
                    }

                    if (schema.FieldsByName.ContainsKey(command.Name))
                    {
                        e(T.Get("schemas.fieldNameAlreadyExists"));
                    }
                }
            });
        }
Ejemplo n.º 16
0
        public static void CanUpdate(Schema schema, UpdateField command)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            Validate.It(() => "Cannot update field.", e =>
            {
                if (command.Properties == null)
                {
                    e(Not.Defined("Properties"), nameof(command.Properties));
                }
                else
                {
                    var errors = FieldPropertiesValidator.Validate(command.Properties);

                    errors.Foreach(x => x.WithPrefix(nameof(command.Properties)).AddTo(e));
                }
            });
        }
Ejemplo n.º 17
0
        public static void CanDelete(DeleteField command, Schema schema)
        {
            Guard.NotNull(command, nameof(command));

            GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);
        }
Ejemplo n.º 18
0
        public static void CanLock(LockField command, Schema schema)
        {
            Guard.NotNull(command, nameof(command));

            GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, true);
        }