-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from Takasaki-Studio/dev
rename BaseViewModel.cs to BaseValidationRecord.cs
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using FluentValidation; | ||
using FluentValidation.Results; | ||
using Lina.Common.Interfaces; | ||
|
||
namespace Lina.ViewModels; | ||
|
||
/// <summary> | ||
/// Base class to view model with basic validation using <a href="https://docs.fluentvalidation.net/en/latest/">Fluent Validation</a> | ||
/// </summary> | ||
/// <typeparam name="TModel">Self ref class</typeparam> | ||
/// <typeparam name="TValidationClass">Validation class implementation</typeparam> | ||
public abstract record BaseValidationRecord<TModel, TValidationClass> : IValidate, IBaseValidate<TModel, TValidationClass> | ||
where TValidationClass : IValidator<TModel> | ||
{ | ||
/// <summary> | ||
/// Validate view model with class validation and throw exception if failure | ||
/// </summary> | ||
/// <exception cref="ValidationException">Failure validation information</exception> | ||
public virtual async ValueTask Validate() | ||
{ | ||
await GetBaseImplementationInstance().BaseValidate(); | ||
} | ||
|
||
/// <summary> | ||
/// Get validation errors | ||
/// </summary> | ||
/// <returns>Failure validation information</returns> | ||
public virtual async Task<ValidationResult> GetErrors() | ||
{ | ||
return await GetBaseImplementationInstance().BaseGetErrors(); | ||
} | ||
|
||
/// <summary> | ||
/// Verify if validation pass | ||
/// </summary> | ||
/// <returns>If valid</returns> | ||
public virtual async ValueTask<bool> IsValid() | ||
{ | ||
return await GetBaseImplementationInstance().BaseIsValid(); | ||
} | ||
|
||
private IBaseValidate<TModel, TValidationClass> GetBaseImplementationInstance() => this; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters