示例#1
0
        public static void CanChangeContentStatus(ISchemaEntity schema, bool isPending, Status status, ChangeContentStatus command)
        {
            Guard.NotNull(command, nameof(command));

            if (schema.SchemaDef.IsSingleton && command.Status != Status.Published)
            {
                throw new DomainException("Singleton content archived or unpublished.");
            }

            Validate.It(() => "Cannot change status.", e =>
            {
                if (!StatusFlow.Exists(command.Status))
                {
                    e(Not.Valid("Status"), nameof(command.Status));
                }
                else if (!StatusFlow.CanChange(status, command.Status))
                {
                    if (status == command.Status && status == Status.Published)
                    {
                        if (!isPending)
                        {
                            e("Content has no changes to publish.", nameof(command.Status));
                        }
                    }
                    else
                    {
                        e($"Cannot change status from {status} to {command.Status}.", nameof(command.Status));
                    }
                }

                if (command.DueTime.HasValue && command.DueTime.Value < SystemClock.Instance.GetCurrentInstant())
                {
                    e("Due time must be in the future.", nameof(command.DueTime));
                }
            });
        }