public static Task CanUpdate(UpdateRule command, Guid appId, IAppProvider appProvider, Rule rule) { Guard.NotNull(command); return(Validate.It(() => "Cannot update rule.", async e => { if (command.Trigger == null && command.Action == null && command.Name == null) { e(Not.Defined("Either trigger, action or name"), nameof(command.Trigger), nameof(command.Action)); } if (command.Trigger != null) { var errors = await RuleTriggerValidator.ValidateAsync(appId, command.Trigger, appProvider); errors.Foreach(x => x.AddTo(e)); } if (command.Action != null) { var errors = command.Action.Validate(); errors.Foreach(x => x.AddTo(e)); } if (command.Name != null && string.Equals(rule.Name, command.Name)) { e(Not.New("Rule", "name"), nameof(command.Name)); } })); }
public static Task CanCreate(CreateRule command, IAppProvider appProvider) { Guard.NotNull(command); return(Validate.It(() => "Cannot create rule.", async e => { if (command.Trigger == null) { e(Not.Defined("Trigger"), nameof(command.Trigger)); } else { var errors = await RuleTriggerValidator.ValidateAsync(command.AppId.Id, command.Trigger, appProvider); errors.Foreach(x => x.AddTo(e)); } if (command.Action == null) { e(Not.Defined("Action"), nameof(command.Action)); } else { var errors = command.Action.Validate(); errors.Foreach(x => x.AddTo(e)); } })); }
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 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 CanUpdate(UpdateRule command, IRuleEntity rule, IAppProvider appProvider) { Guard.NotNull(command, nameof(command)); return(Validate.It(async e => { if (command.Trigger != null) { var errors = await RuleTriggerValidator.ValidateAsync(rule.AppId.Id, command.Trigger, appProvider); errors.Foreach((x, _) => x.AddTo(e)); } if (command.Action != null) { var errors = command.Action.Validate(); errors.Foreach((x, _) => x.AddTo(e)); } })); }