public static Task CanUpdate(UpdateRule command, IAppProvider appProvider) { Guard.NotNull(command, nameof(command)); return(Validate.It(() => "Cannot update rule.", async error => { if (command.Trigger == null && command.Action == null) { error(new ValidationError("Either trigger or action must be defined.", nameof(command.Trigger), nameof(command.Action))); } if (command.Trigger != null) { var errors = await RuleTriggerValidator.ValidateAsync(command.AppId.Name, command.Trigger, appProvider); errors.Foreach(error); } if (command.Action != null) { var errors = await RuleActionValidator.ValidateAsync(command.Action); errors.Foreach(error); } })); }
public static Task CanCreate(CreateRule command, ISchemaProvider schemas) { Guard.NotNull(command, nameof(command)); return(Validate.It(() => "Cannot create rule.", async error => { if (command.Trigger == null) { error(new ValidationError("Trigger must be defined.", nameof(command.Trigger))); } else { var errors = await RuleTriggerValidator.ValidateAsync(command.Trigger, schemas); errors.Foreach(error); } if (command.Action == null) { error(new ValidationError("Trigger must be defined.", nameof(command.Action))); } else { var errors = await RuleActionValidator.ValidateAsync(command.Action); errors.Foreach(error); } })); }
public static Task <IEnumerable <ValidationError> > ValidateAsync(RuleAction action) { Guard.NotNull(action, nameof(action)); var visitor = new RuleActionValidator(); return(action.Accept(visitor)); }