-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApiResult.cs
More file actions
41 lines (36 loc) · 1.18 KB
/
ApiResult.cs
File metadata and controls
41 lines (36 loc) · 1.18 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
using System.Collections.Generic;
using System.Linq;
namespace BoardGamesApi.Models
{
/// <summary>
/// Encapsulates an API result with success flag, errors (if any) and result object.
/// </summary>
/// <typeparam name="T">Type of the result.</typeparam>
public class ApiResult<T>
{
/// <summary>
/// Gets the API error string or empty string if there are no errors.
/// </summary>
public string Error => string.Join("; ", Errors);
/// <summary>
/// Gets the error list.
/// </summary>
public IList<string> Errors { get; } = new List<string>();
/// <summary>
/// Gets the value indicating whether the API call was successful or not.
/// </summary>
public bool IsSuccess => !Errors.Any();
/// <summary>
/// Gets or sets the data object.
/// </summary>
public T Data { get; set; }
/// <summary>
/// Add the error to the error list.
/// </summary>
/// <param name="error">An error to add to errors list.</param>
public void AddError(string error)
{
Errors.Add(error);
}
}
}