-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMatrixQuestionRequestValidator.cs
More file actions
54 lines (41 loc) · 1.7 KB
/
MatrixQuestionRequestValidator.cs
File metadata and controls
54 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using FastEndpoints;
using FluentValidation;
using Vote.Monitor.Core.Validators;
using Vote.Monitor.Form.Module.Requests;
namespace Vote.Monitor.Form.Module.Validators;
public class MatrixQuestionRequestValidator : Validator<MatrixQuestionRequest>
{
public MatrixQuestionRequestValidator(List<string> languages)
{
RuleFor(x => x.Id).NotEmpty();
RuleFor(x => x.QuestionType).NotEmpty();
RuleFor(x => x.Text)
.SetValidator(new PartiallyTranslatedStringValidator(languages));
RuleFor(x => x.Helptext)
.SetValidator(new PartiallyTranslatedStringValidator(languages))
.When(x => x.Helptext != null);
RuleFor(x => x.Code)
.NotEmpty()
.MaximumLength(256);
RuleForEach(x => x.Options)
.SetValidator(new MatrixOptionRequestValidator(languages));
RuleFor(x => x.Options)
.Must(options =>
{
var groupedOptionIds = options.GroupBy(o => o.Id, (id, group) => new { id, count = group.Count() });
return groupedOptionIds.All(g => g.count == 1);
})
.WithMessage("Duplicated id found");
RuleForEach(x => x.Rows)
.SetValidator(new MatrixRowRequestValidator(languages));
RuleFor(x => x.Rows)
.Must(options =>
{
var groupedOptionIds = options.GroupBy(o => o.Id, (id, group) => new { id, count = group.Count() });
return groupedOptionIds.All(g => g.count == 1);
})
.WithMessage("Duplicated id found");
RuleFor(x => x.DisplayLogic)
.SetValidator(new DisplayLogicRequestValidator());
}
}