-
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 #7 from TheKornelM/dev
New translations, class data validators
- Loading branch information
Showing
8 changed files
with
223 additions
and
8 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,24 @@ | ||
using FluentValidation; | ||
using System.Resources; | ||
|
||
namespace SchoolManagerModel.Validators; | ||
|
||
public class CharLetterValidator : AbstractValidator<string> | ||
{ | ||
public CharLetterValidator(ResourceManager resourceManager) | ||
{ | ||
RuleFor(x => x) | ||
.Length(1) | ||
.WithMessage(resourceManager.GetString("CanContainOnly1Letter")) // Check the length first | ||
.DependentRules(() => | ||
{ | ||
RuleFor(x => x) | ||
.Must(cls => cls.Length == 1 && Char.IsLetter(cls[0])) | ||
.WithMessage(resourceManager.GetString("MustBeALetter")) | ||
.When(cls => cls.Length == 1); // Ensure length is 1 before accessing the character | ||
}); | ||
|
||
|
||
|
||
} | ||
} |
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,15 @@ | ||
using FluentValidation; | ||
using System.Resources; | ||
|
||
namespace SchoolManagerModel.Validators; | ||
|
||
public class ClassStringValidator : AbstractValidator<(string year, string cls)> | ||
{ | ||
public ClassStringValidator(ResourceManager resourceManager) | ||
{ | ||
RuleFor(x => x.year) | ||
.SetValidator(new ClassYearStringValidator(resourceManager)); | ||
RuleFor(x => x.cls) | ||
.SetValidator(new CharLetterValidator(resourceManager)); | ||
} | ||
} |
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,22 @@ | ||
using FluentValidation; | ||
using System.Resources; | ||
|
||
namespace SchoolManagerModel.Validators; | ||
|
||
public class ClassYearStringValidator : AbstractValidator<string> | ||
{ | ||
public ClassYearStringValidator(ResourceManager resourceManager) | ||
{ | ||
RuleFor(x => x) | ||
.SetValidator(new NumberValidator(resourceManager)) | ||
.DependentRules(() => | ||
{ | ||
// Check only if it is number | ||
RuleFor(x => x) | ||
.Must(x => int.TryParse(x, out var num) && num > 0) | ||
.When(x => int.TryParse(x, out var _)) | ||
.WithMessage(resourceManager.GetString("MustBeGreaterThan0")); | ||
|
||
}); | ||
} | ||
} |
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,14 @@ | ||
using FluentValidation; | ||
using System.Resources; | ||
|
||
namespace SchoolManagerModel.Validators; | ||
|
||
public class NumberValidator : AbstractValidator<string> | ||
{ | ||
public NumberValidator(ResourceManager resourceManager) | ||
{ | ||
RuleFor(a => a) | ||
.Must(x => int.TryParse(x, out var val)) | ||
.WithMessage(resourceManager.GetString("MustBeNumber")); | ||
} | ||
} |