public CreateSavedFilterCommandValidator(
            ISavedFilterValidator savedFilterValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, cancellationToken) => NotExistsASavedFilterWithSameTitleForPersonOnProject(command.Title, command.ProjectName, cancellationToken))
            .WithMessage(command => $"A saved filter with this title already exists! Title={command.Title}");

            async Task <bool> NotExistsASavedFilterWithSameTitleForPersonOnProject(string title, string projectName, CancellationToken cancellationToken)
            => !await savedFilterValidator.ExistsWithSameTitleForPersonInProjectAsync(title, projectName, cancellationToken);
        }
예제 #2
0
        public DeleteSavedFilterCommandValidator(
            ISavedFilterValidator savedFilterValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingSavedFilterAsync(command.SavedFilterId, token))
            .WithMessage(command => $"Saved filter doesn't exist! Saved filter={command.SavedFilterId}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> BeAnExistingSavedFilterAsync(int savedFilterId, CancellationToken token)
            => await savedFilterValidator.ExistsAsync(savedFilterId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }
        public UpdateSavedFilterCommandValidator(
            ISavedFilterValidator savedFilterValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingSavedFilterAsync(command.SavedFilterId, token))
            .WithMessage(command => $"Saved filter doesn't exist! Saved filter={command.SavedFilterId}")
            .MustAsync((command, token) => HaveAUniqueTitleForPerson(command.Title, command.SavedFilterId, token))
            .WithMessage(command => $"A saved filter with this title already exists! Title={command.Title}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> BeAnExistingSavedFilterAsync(int savedFilterId, CancellationToken token)
            => await savedFilterValidator.ExistsAsync(savedFilterId, token);
            async Task <bool> HaveAUniqueTitleForPerson(string title, int savedFilterId, CancellationToken token)
            => !await savedFilterValidator.ExistsAnotherWithSameTitleForPersonInProjectAsync(savedFilterId, title, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }