-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMatrixQuestion.cs
More file actions
97 lines (82 loc) · 2.91 KB
/
MatrixQuestion.cs
File metadata and controls
97 lines (82 loc) · 2.91 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System.Runtime.InteropServices.JavaScript;
using Microsoft.AspNetCore.Http.HttpResults;
using NPOI.SS.Formula.Functions;
using Vote.Monitor.Core.Models;
namespace Vote.Monitor.Domain.Entities.FormBase.Questions;
public record MatrixQuestion : BaseQuestion
{
public IReadOnlyList<MatrixOption> Options { get; private set; }
public IReadOnlyList<MatrixRow> Rows { get; private set; }
[JsonConstructor]
internal MatrixQuestion(Guid id,
string code,
TranslatedString text,
TranslatedString? helptext,
DisplayLogic? displayLogic,
IReadOnlyList<MatrixOption> options,
IReadOnlyList<MatrixRow> rows) : base(id, code, text, helptext, displayLogic)
{
Options = options;
Rows = rows;
}
protected override void AddTranslationsInternal(string languageCode)
{
foreach (var option in Options)
{
option.AddTranslation(languageCode);
}
foreach (var row in Rows)
{
row.AddTranslation(languageCode);
}
}
protected override void RemoveTranslationInternal(string languageCode)
{
foreach (var option in Options)
{
option.RemoveTranslation(languageCode);
}
foreach (var row in Rows)
{
row.RemoveTranslation(languageCode);
}
}
protected override TranslationStatus InternalGetTranslationStatus(string baseLanguageCode, string languageCode)
{
bool anyMissingInOptions = Options.Any(x => string.IsNullOrWhiteSpace(x.Text[languageCode]));
bool anyMissingInRows = Rows.Any(x => string.IsNullOrWhiteSpace(x.Text[languageCode]));
return anyMissingInOptions || anyMissingInRows
? TranslationStatus.MissingTranslations
: TranslationStatus.Translated;
}
protected override void InternalTrimTranslations(IEnumerable<string> languages)
{
var languagesArray = languages as string[] ?? languages.ToArray();
foreach (var option in Options)
{
option.TrimTranslations(languagesArray);
}
foreach (var row in Rows)
{
row.TrimTranslations(languagesArray);
}
}
public static MatrixQuestion Create(Guid id,
string code,
TranslatedString text,
TranslatedString? helptext,
DisplayLogic? displayLogic,
IReadOnlyList<MatrixOption> options,
IReadOnlyList<MatrixRow> rows)
=> new(id, code, text, helptext, displayLogic, options, rows);
public virtual bool Equals(MatrixQuestion? other)
{
bool options = base.Equals(other) && Options.SequenceEqual(other.Options);
bool rows = base.Equals(other) && Rows.SequenceEqual(other.Rows);
return options && rows;
}
public override int GetHashCode()
{
return HashCode.Combine(base.GetHashCode(), Options, Rows);
}
}