2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
- using Microsoft . AspNetCore . Http ;
6
5
using Microsoft . EntityFrameworkCore ;
7
6
using System . Diagnostics . CodeAnalysis ;
7
+ using System . Net ;
8
8
9
9
namespace CommunityToolkit . Datasync . Server . EntityFrameworkCore ;
10
10
@@ -109,7 +109,7 @@ internal async Task WrapExceptionAsync(string id, Func<Task> action, Cancellatio
109
109
}
110
110
catch ( DbUpdateConcurrencyException ex )
111
111
{
112
- throw new HttpException ( StatusCodes . Status409Conflict , ex . Message , ex ) { Payload = await GetEntityAsync ( id , cancellationToken ) . ConfigureAwait ( false ) } ;
112
+ throw new HttpException ( ( int ) HttpStatusCode . Conflict , ex . Message , ex ) { Payload = await GetEntityAsync ( id , cancellationToken ) . ConfigureAwait ( false ) } ;
113
113
}
114
114
catch ( DbUpdateException ex )
115
115
{
@@ -136,7 +136,7 @@ await WrapExceptionAsync(entity.Id, async () =>
136
136
// We do not use Any() here because it is not supported by all providers (e.g. Cosmos)
137
137
if ( DataSet . Count ( x => x . Id == entity . Id ) > 0 )
138
138
{
139
- throw new HttpException ( StatusCodes . Status409Conflict ) { Payload = await GetEntityAsync ( entity . Id , cancellationToken ) . ConfigureAwait ( false ) } ;
139
+ throw new HttpException ( ( int ) HttpStatusCode . Conflict ) { Payload = await GetEntityAsync ( entity . Id , cancellationToken ) . ConfigureAwait ( false ) } ;
140
140
}
141
141
142
142
UpdateManagedProperties ( entity ) ;
@@ -150,17 +150,17 @@ public virtual async ValueTask DeleteAsync(string id, byte[]? version = null, Ca
150
150
{
151
151
if ( string . IsNullOrEmpty ( id ) )
152
152
{
153
- throw new HttpException ( StatusCodes . Status400BadRequest , "ID is required" ) ;
153
+ throw new HttpException ( ( int ) HttpStatusCode . BadRequest , "ID is required" ) ;
154
154
}
155
155
156
156
await WrapExceptionAsync ( id , async ( ) =>
157
157
{
158
- TEntity storedEntity = await DataSet . FindAsync ( new object [ ] { id } , cancellationToken ) . ConfigureAwait ( false )
159
- ?? throw new HttpException ( StatusCodes . Status404NotFound ) ;
158
+ TEntity storedEntity = await DataSet . FindAsync ( [ id ] , cancellationToken ) . ConfigureAwait ( false )
159
+ ?? throw new HttpException ( ( int ) HttpStatusCode . NotFound ) ;
160
160
161
161
if ( version ? . Length > 0 && ! storedEntity . Version . SequenceEqual ( version ) )
162
162
{
163
- throw new HttpException ( StatusCodes . Status412PreconditionFailed ) { Payload = await GetEntityAsync ( id , cancellationToken ) . ConfigureAwait ( false ) } ;
163
+ throw new HttpException ( ( int ) HttpStatusCode . PreconditionFailed ) { Payload = await GetEntityAsync ( id , cancellationToken ) . ConfigureAwait ( false ) } ;
164
164
}
165
165
166
166
_ = DataSet . Remove ( storedEntity ) ;
@@ -173,11 +173,11 @@ public virtual async ValueTask<TEntity> ReadAsync(string id, CancellationToken c
173
173
{
174
174
if ( string . IsNullOrEmpty ( id ) )
175
175
{
176
- throw new HttpException ( StatusCodes . Status400BadRequest , "ID is required" ) ;
176
+ throw new HttpException ( ( int ) HttpStatusCode . BadRequest , "ID is required" ) ;
177
177
}
178
178
179
179
TEntity entity = await DataSet . AsNoTracking ( ) . SingleOrDefaultAsync ( x => x . Id == id , cancellationToken ) . ConfigureAwait ( false )
180
- ?? throw new HttpException ( StatusCodes . Status404NotFound ) ;
180
+ ?? throw new HttpException ( ( int ) HttpStatusCode . NotFound ) ;
181
181
182
182
return entity ;
183
183
}
@@ -187,17 +187,17 @@ public virtual async ValueTask ReplaceAsync(TEntity entity, byte[]? version = nu
187
187
{
188
188
if ( string . IsNullOrEmpty ( entity . Id ) )
189
189
{
190
- throw new HttpException ( StatusCodes . Status400BadRequest , "ID is required" ) ;
190
+ throw new HttpException ( ( int ) HttpStatusCode . BadRequest , "ID is required" ) ;
191
191
}
192
192
193
193
await WrapExceptionAsync ( entity . Id , async ( ) =>
194
194
{
195
195
TEntity storedEntity = await DataSet . FindAsync ( new object [ ] { entity . Id } , cancellationToken ) . ConfigureAwait ( false )
196
- ?? throw new HttpException ( StatusCodes . Status404NotFound ) ;
196
+ ?? throw new HttpException ( ( int ) HttpStatusCode . NotFound ) ;
197
197
198
198
if ( version ? . Length > 0 && ! storedEntity . Version . SequenceEqual ( version ) )
199
199
{
200
- throw new HttpException ( StatusCodes . Status412PreconditionFailed ) { Payload = await GetEntityAsync ( entity . Id , cancellationToken ) . ConfigureAwait ( false ) } ;
200
+ throw new HttpException ( ( int ) HttpStatusCode . PreconditionFailed ) { Payload = await GetEntityAsync ( entity . Id , cancellationToken ) . ConfigureAwait ( false ) } ;
201
201
}
202
202
203
203
UpdateManagedProperties ( entity ) ;
0 commit comments