aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/Models/KnownProblem.cs
blob: c92872f4f9c95427cd5efdf9f6214e2fccb25cf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace Quality.Storage.Api.Models;

public class KnownProblemModel(string title = default, string subtitle = default, Dictionary<string, string[]> errors = default)
{
	public string Title { get; set; } = title;
	public string Subtitle { get; set; } = subtitle;
	public Dictionary<string, string[]> Errors { get; set; } = errors ?? new Dictionary<string, string[]>();
	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());
        }
    }
}