|
4 | 4 | using Microsoft.AspNet.OData.Common;
|
5 | 5 | using Microsoft.AspNet.OData.Results;
|
6 | 6 | using Microsoft.AspNetCore.Mvc;
|
| 7 | +using Microsoft.OData; |
7 | 8 |
|
8 | 9 | namespace Microsoft.AspNet.OData
|
9 | 10 | {
|
@@ -51,5 +52,131 @@ protected virtual UpdatedODataResult<TEntity> Updated<TEntity>(TEntity entity)
|
51 | 52 |
|
52 | 53 | return new UpdatedODataResult<TEntity>(entity);
|
53 | 54 | }
|
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce a Bad Request (400) response. |
| 58 | + /// </summary> |
| 59 | + /// <param name="message">Error Message</param> |
| 60 | + /// <returns>A <see cref="BadRequestODataResult"/> with the specified values.</returns> |
| 61 | + protected virtual BadRequestODataResult BadRequest(string message) |
| 62 | + { |
| 63 | + return new BadRequestODataResult(message); |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce a Bad Request (400) response. |
| 68 | + /// </summary> |
| 69 | + /// <param name="odataError">Parameter of type <see cref="ODataError"/>.</param> |
| 70 | + /// <returns>A <see cref="BadRequestODataResult"/> with the specified values.</returns> |
| 71 | + protected virtual BadRequestODataResult BadRequest(ODataError odataError) |
| 72 | + { |
| 73 | + return new BadRequestODataResult(odataError); |
| 74 | + } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce a Not Found (404) response. |
| 78 | + /// </summary> |
| 79 | + /// <param name="message">Error Message</param> |
| 80 | + /// <returns>A <see cref="NotFoundODataResult"/> with the specified values.</returns> |
| 81 | + protected virtual NotFoundODataResult NotFound(string message) |
| 82 | + { |
| 83 | + return new NotFoundODataResult(message); |
| 84 | + } |
| 85 | + |
| 86 | + /// <summary> |
| 87 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce a Not Found (404) response. |
| 88 | + /// </summary> |
| 89 | + /// <param name="odataError">Parameter of type <see cref="ODataError"/>.</param> |
| 90 | + /// <returns>A <see cref="NotFoundODataResult"/> with the specified values.</returns> |
| 91 | + protected virtual NotFoundODataResult NotFound(ODataError odataError) |
| 92 | + { |
| 93 | + return new NotFoundODataResult(odataError); |
| 94 | + } |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce a Unauthorized (401) response. |
| 98 | + /// </summary> |
| 99 | + /// <param name="message">Error Message</param> |
| 100 | + /// <returns>An <see cref="UnauthorizedODataResult"/> with the specified values.</returns> |
| 101 | + protected virtual UnauthorizedODataResult Unauthorized(string message) |
| 102 | + { |
| 103 | + return new UnauthorizedODataResult(message); |
| 104 | + } |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce a Unauthorized (401) response. |
| 108 | + /// </summary> |
| 109 | + /// <param name="odataError">Parameter of type <see cref="ODataError"/>.</param> |
| 110 | + /// <returns>An <see cref="UnauthorizedODataResult"/> with the specified values.</returns> |
| 111 | + protected virtual UnauthorizedODataResult Unauthorized(ODataError odataError) |
| 112 | + { |
| 113 | + return new UnauthorizedODataResult(odataError); |
| 114 | + } |
| 115 | + |
| 116 | + // ConflictResult and UnprocessableEntityResult were introduced in AspNet core 2.1, which is implemented from .Net standard 2.1 |
| 117 | + // https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.conflict?view=aspnetcore-2.1 |
| 118 | + // https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.unprocessableentityresult?view=aspnetcore-2.1 |
| 119 | +#if !NETSTANDARD2_0 |
| 120 | + /// <summary> |
| 121 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce a Conflict (409) response. |
| 122 | + /// </summary> |
| 123 | + /// <param name="message">Error Message</param> |
| 124 | + /// <returns>A <see cref="ConflictODataResult"/> with the specified values.</returns> |
| 125 | + protected virtual ConflictODataResult Conflict(string message) |
| 126 | + { |
| 127 | + return new ConflictODataResult(message); |
| 128 | + } |
| 129 | + |
| 130 | + /// <summary> |
| 131 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce a Conflict (409) response. |
| 132 | + /// </summary> |
| 133 | + /// <param name="odataError">Parameter of type <see cref="ODataError"/>.</param> |
| 134 | + /// <returns>A <see cref="ConflictODataResult"/> with the specified values.</returns> |
| 135 | + protected virtual ConflictODataResult Conflict(ODataError odataError) |
| 136 | + { |
| 137 | + return new ConflictODataResult(odataError); |
| 138 | + } |
| 139 | + |
| 140 | + /// <summary> |
| 141 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce an UnprocessableEntity (422) response. |
| 142 | + /// </summary> |
| 143 | + /// <param name="message">Error Message</param> |
| 144 | + /// <returns>An <see cref="UnprocessableEntityODataResult"/> with the specified values.</returns> |
| 145 | + protected virtual UnprocessableEntityODataResult UnprocessableEntity(string message) |
| 146 | + { |
| 147 | + return new UnprocessableEntityODataResult(message); |
| 148 | + } |
| 149 | + |
| 150 | + /// <summary> |
| 151 | + /// Creates a <see cref="StatusCodeResult"/> that when executed will produce an UnprocessableEntity (422) response. |
| 152 | + /// </summary> |
| 153 | + /// <param name="odataError">Parameter of type <see cref="ODataError"/>.</param> |
| 154 | + /// <returns>An <see cref="UnprocessableEntityODataResult"/> with the specified values.</returns> |
| 155 | + protected virtual UnprocessableEntityODataResult UnprocessableEntity(ODataError odataError) |
| 156 | + { |
| 157 | + return new UnprocessableEntityODataResult(odataError); |
| 158 | + } |
| 159 | +#endif |
| 160 | + |
| 161 | + /// <summary> |
| 162 | + /// Creates a <see cref="ActionResult"/> that when executed will produce an <see cref="ODataError"/> response. |
| 163 | + /// </summary> |
| 164 | + /// <param name="errorCode">Http Error code.</param> |
| 165 | + /// <param name="message">Http Error Message.</param> |
| 166 | + /// <returns>An <see cref="Microsoft.AspNet.OData.Results.ODataErrorResult"/> with the specified values.</returns> |
| 167 | + protected virtual ODataErrorResult ODataErrorResult(string errorCode, string message) |
| 168 | + { |
| 169 | + return new ODataErrorResult(errorCode, message); |
| 170 | + } |
| 171 | + |
| 172 | + /// <summary> |
| 173 | + /// Creates a <see cref="ActionResult"/> that when executed will produce an <see cref="ODataError"/> response. |
| 174 | + /// </summary> |
| 175 | + /// <param name="odataError"><see cref="ODataError"/>.</param> |
| 176 | + /// <returns>An <see cref="Microsoft.AspNet.OData.Results.ODataErrorResult"/> with the specified values.</returns> |
| 177 | + protected virtual ODataErrorResult ODataErrorResult(ODataError odataError) |
| 178 | + { |
| 179 | + return new ODataErrorResult(odataError); |
| 180 | + } |
54 | 181 | }
|
55 | 182 | }
|
0 commit comments