| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Text; |
| | 4 | |
|
| | 5 | | namespace MUNity.Schema.Extensions |
| | 6 | | { |
| | 7 | | public static class ResponseBuilderExtensions |
| | 8 | | { |
| | 9 | | public static void AddNoPermissionError(this AbstractResponse response, string description = "") |
| 0 | 10 | | { |
| 0 | 11 | | response.HasError = true; |
| 0 | 12 | | response.Errors.Add(new ResponseError() |
| 0 | 13 | | { |
| 0 | 14 | | ErrorType = ErrorTypes.NoPermission, |
| 0 | 15 | | Description = description |
| 0 | 16 | | }); |
| 0 | 17 | | } |
| | 18 | |
|
| | 19 | | public static void AddInvalidDataError(this AbstractResponse response, string description, string parameter = "" |
| 0 | 20 | | { |
| 0 | 21 | | response.HasError = true; |
| 0 | 22 | | response.Errors.Add(new ResponseError() |
| 0 | 23 | | { |
| 0 | 24 | | ErrorType = ErrorTypes.InvalidData, |
| 0 | 25 | | Description = description, |
| 0 | 26 | | ParameterName = parameter |
| 0 | 27 | | }); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | public static void AddMissingDataError(this AbstractResponse response, string description, string parameter) |
| 0 | 31 | | { |
| 0 | 32 | | response.HasError = true; |
| 0 | 33 | | response.Errors.Add(new ResponseError() |
| 0 | 34 | | { |
| 0 | 35 | | ErrorType = ErrorTypes.MissingData, |
| 0 | 36 | | Description = description, |
| 0 | 37 | | ParameterName = parameter |
| 0 | 38 | | }); |
| 0 | 39 | | } |
| | 40 | |
|
| | 41 | | public static void AddNotFoundError(this AbstractResponse response, string parameterName) |
| 0 | 42 | | { |
| 0 | 43 | | response.HasError = true; |
| 0 | 44 | | response.Errors.Add(new ResponseError() |
| 0 | 45 | | { |
| 0 | 46 | | ErrorType = ErrorTypes.InvalidData, |
| 0 | 47 | | Description = $"The data for {parameterName} was not found.", |
| 0 | 48 | | ParameterName = parameterName |
| 0 | 49 | | }); |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | public static void AddConferenceNotFoundError(this AbstractResponse response) => |
| 0 | 53 | | response.AddInvalidDataError("The needed Conference was not found"); |
| | 54 | |
|
| | 55 | | public static void AddCommitteeNotFoundError(this AbstractResponse response) => |
| 0 | 56 | | response.AddInvalidDataError("The needed Committee was not found"); |
| | 57 | |
|
| | 58 | |
|
| | 59 | | public static void AddWarning(this AbstractResponse response, string description, string parameter = null) |
| 0 | 60 | | { |
| 0 | 61 | | response.Errors.Add(new ResponseError() |
| 0 | 62 | | { |
| 0 | 63 | | ErrorType = ErrorTypes.MissingData, |
| 0 | 64 | | Description = description, |
| 0 | 65 | | ParameterName = parameter |
| 0 | 66 | | }); |
| 0 | 67 | | } |
| | 68 | | } |
| | 69 | | } |