| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="FileExportViewModelValidator.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using FluentValidation; |
| | | 8 | | using MyNet.Observable; |
| | | 9 | | using MyNet.UI.Resources; |
| | | 10 | | |
| | | 11 | | namespace MyNet.UI.ViewModels.Export; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// FluentValidation rules for <see cref="FileExportViewModelBase{T}"/>. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <typeparam name="T">The exported item type.</typeparam> |
| | | 17 | | public class FileExportViewModelValidator<T> : AbstractValidator<FileExportViewModelBase<T>> |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Initializes a new instance of the <see cref="FileExportViewModelValidator{T}"/> class. |
| | | 21 | | /// </summary> |
| | 0 | 22 | | public FileExportViewModelValidator() |
| | | 23 | | { |
| | 0 | 24 | | Include(new ExportViewModelValidator<T>()); |
| | | 25 | | |
| | 0 | 26 | | RuleFor(x => x.Destination) |
| | 0 | 27 | | .NotEmpty() |
| | 0 | 28 | | .WithRequiredLocalizedMessage(nameof(FileExportViewModelBase<>.Destination)); |
| | | 29 | | |
| | 0 | 30 | | RuleFor(x => x.Destination) |
| | 0 | 31 | | .Must((vm, destination) => vm.FileType.IsValidPath(destination!)) |
| | 0 | 32 | | .When(x => !string.IsNullOrWhiteSpace(x.Destination)) |
| | 0 | 33 | | .WithMessage(_ => MessageResources.FileHasInvalidExtensionError); |
| | 0 | 34 | | } |
| | | 35 | | } |
| | | 36 | | |