public static Task CanUpdate(UpdateRule command, Guid appId, 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 is required.", nameof(command.Trigger), nameof(command.Action))); } if (command.Trigger != null) { var errors = await RuleTriggerValidator.ValidateAsync(appId, 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, IAppProvider appProvider) { Guard.NotNull(command, nameof(command)); return(Validate.It(() => "Cannot create rule.", async error => { if (command.Trigger == null) { error(new ValidationError("Trigger is required.", nameof(command.Trigger))); } else { var errors = await RuleTriggerValidator.ValidateAsync(command.AppId.Id, command.Trigger, appProvider); errors.Foreach(error); } if (command.Action == null) { error(new ValidationError("Trigger is required.", 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)); }