22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5- using Microsoft . AspNetCore . Http ;
65using Microsoft . EntityFrameworkCore ;
76using System . Diagnostics . CodeAnalysis ;
7+ using System . Net ;
88
99namespace CommunityToolkit . Datasync . Server . EntityFrameworkCore ;
1010
@@ -109,7 +109,7 @@ internal async Task WrapExceptionAsync(string id, Func<Task> action, Cancellatio
109109 }
110110 catch ( DbUpdateConcurrencyException ex )
111111 {
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 ) } ;
113113 }
114114 catch ( DbUpdateException ex )
115115 {
@@ -136,7 +136,7 @@ await WrapExceptionAsync(entity.Id, async () =>
136136 // We do not use Any() here because it is not supported by all providers (e.g. Cosmos)
137137 if ( DataSet . Count ( x => x . Id == entity . Id ) > 0 )
138138 {
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 ) } ;
140140 }
141141
142142 UpdateManagedProperties ( entity ) ;
@@ -150,17 +150,17 @@ public virtual async ValueTask DeleteAsync(string id, byte[]? version = null, Ca
150150 {
151151 if ( string . IsNullOrEmpty ( id ) )
152152 {
153- throw new HttpException ( StatusCodes . Status400BadRequest , "ID is required" ) ;
153+ throw new HttpException ( ( int ) HttpStatusCode . BadRequest , "ID is required" ) ;
154154 }
155155
156156 await WrapExceptionAsync ( id , async ( ) =>
157157 {
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 ) ;
160160
161161 if ( version ? . Length > 0 && ! storedEntity . Version . SequenceEqual ( version ) )
162162 {
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 ) } ;
164164 }
165165
166166 _ = DataSet . Remove ( storedEntity ) ;
@@ -173,11 +173,11 @@ public virtual async ValueTask<TEntity> ReadAsync(string id, CancellationToken c
173173 {
174174 if ( string . IsNullOrEmpty ( id ) )
175175 {
176- throw new HttpException ( StatusCodes . Status400BadRequest , "ID is required" ) ;
176+ throw new HttpException ( ( int ) HttpStatusCode . BadRequest , "ID is required" ) ;
177177 }
178178
179179 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 ) ;
181181
182182 return entity ;
183183 }
@@ -187,17 +187,17 @@ public virtual async ValueTask ReplaceAsync(TEntity entity, byte[]? version = nu
187187 {
188188 if ( string . IsNullOrEmpty ( entity . Id ) )
189189 {
190- throw new HttpException ( StatusCodes . Status400BadRequest , "ID is required" ) ;
190+ throw new HttpException ( ( int ) HttpStatusCode . BadRequest , "ID is required" ) ;
191191 }
192192
193193 await WrapExceptionAsync ( entity . Id , async ( ) =>
194194 {
195195 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 ) ;
197197
198198 if ( version ? . Length > 0 && ! storedEntity . Version . SequenceEqual ( version ) )
199199 {
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 ) } ;
201201 }
202202
203203 UpdateManagedProperties ( entity ) ;
0 commit comments