aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/src/Models/Misc/KnownProblemModel.cs
blob: 9acc85c736871563a89df8de1b4cac52f7f66358 (plain) (blame)
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
namespace IOL.GreatOffice.Api.Data.Models;

public class KnownProblemModel
{
    public KnownProblemModel(string title = default, string subtitle = default, Dictionary<string, string[]> errors = default) {
        Title = title;
        Subtitle = subtitle;
        Errors = errors ?? new();
    }

    public string Title { get; set; }
    public string Subtitle { get; set; }
    public Dictionary<string, string[]> Errors { get; set; }
    public string TraceId { get; set; }

    public void AddError(string field, string errorText) {
        if (!Errors.ContainsKey(field)) {
            Errors.Add(field, new[] {errorText});
        } else {
            var currentErrors = Errors[field];
            var newErrors = currentErrors.Concat(new[] {errorText});
            Errors.Remove(field);
            Errors.Add(field, newErrors.ToArray());
        }
    }
}