13
13
using Moryx . Serialization ;
14
14
using System . Net ;
15
15
using Moryx . AbstractionLayer . Properties ;
16
+ using Moryx . Asp . Extensions . Exception ;
16
17
using Moryx . Configuration ;
17
-
18
18
namespace Moryx . AbstractionLayer . Products . Endpoints
19
19
{
20
20
/// <summary>
@@ -110,7 +110,7 @@ public ActionResult<long> SaveType(ProductModel newTypeModel)
110
110
var type = ReflectionTool . GetPublicClasses < ProductType > ( t => t . Name == newTypeModel . Type )
111
111
. FirstOrDefault ( ) ;
112
112
if ( type == null )
113
- return NotFound ( Strings . TYPE_NOT_FOUND ) ;
113
+ return NotFound ( new MoryxExceptionResponse { Title = Strings . TYPE_NOT_FOUND } ) ;
114
114
var productType = ( ProductType ) Activator . CreateInstance ( type ) ;
115
115
var newType = _productConverter . ConvertProductBack ( newTypeModel , productType ) ;
116
116
return _productManagement . SaveType ( newType ) ;
@@ -139,7 +139,7 @@ public ActionResult<ProductModel[]> GetTypeByIdentity(string identity = null)
139
139
var productIdentity = new ProductIdentity ( identityArray [ 0 ] , Convert . ToInt16 ( identityArray [ 1 ] ) ) ;
140
140
var productType = _productManagement . LoadType ( productIdentity ) ;
141
141
if ( productType == null )
142
- return NotFound ( Strings . TYPE_NOT_FOUND ) ;
142
+ return NotFound ( new MoryxExceptionResponse { Title = Strings . TYPE_NOT_FOUND } ) ;
143
143
return new ProductModel [ ] { _productConverter . ConvertProduct ( productType , false ) } ;
144
144
}
145
145
@@ -170,11 +170,11 @@ public ActionResult<ProductModel> GetTypeById(long id)
170
170
{
171
171
productType = _productManagement . LoadType ( id ) ;
172
172
}
173
- catch ( ProductNotFoundException )
173
+ catch ( ProductNotFoundException e )
174
174
{
175
175
}
176
176
if ( productType == null )
177
- return NotFound ( Strings . TYPE_NOT_FOUND ) ;
177
+ return NotFound ( new MoryxExceptionResponse { Title = Strings . TYPE_NOT_FOUND } ) ;
178
178
return _productConverter . ConvertProduct ( productType , false ) ;
179
179
}
180
180
@@ -186,7 +186,7 @@ public ActionResult<bool> DeleteType(long id)
186
186
{
187
187
var result = _productManagement . DeleteProduct ( id ) ;
188
188
if ( ! result )
189
- return NotFound ( Strings . TYPE_NOT_FOUND ) ;
189
+ return NotFound ( new MoryxExceptionResponse { Title = Strings . TYPE_NOT_FOUND } ) ;
190
190
return result ;
191
191
}
192
192
@@ -254,7 +254,7 @@ public ActionResult<ProductInstanceModel> GetInstance(long id)
254
254
return BadRequest ( $ "Id was 0") ;
255
255
var productInstance = _productManagement . GetInstance ( id ) ;
256
256
if ( productInstance == null )
257
- return NotFound ( string . Format ( Strings . ProductNotFoundException_Message , id ) ) ;
257
+ return NotFound ( new MoryxExceptionResponse { Title = string . Format ( Strings . ProductNotFoundException_Message , id ) } ) ;
258
258
return _productConverter . ConvertProductInstance ( productInstance ) ;
259
259
}
260
260
@@ -294,7 +294,7 @@ public ActionResult SaveInstance(ProductInstanceModel instanceModel)
294
294
var type = ReflectionTool . GetPublicClasses < IProductType > ( t => t . Name == instanceModel . Type )
295
295
. FirstOrDefault ( ) ;
296
296
if ( type == null )
297
- return NotFound ( string . Format ( Strings . ProductNotFoundException_Message , "null" ) ) ;
297
+ return NotFound ( new MoryxExceptionResponse { Title = string . Format ( Strings . ProductNotFoundException_Message , "null" ) } ) ;
298
298
var productType = ( IProductType ) Activator . CreateInstance ( type ) ;
299
299
var productInstance = _productConverter . ConvertProductInstanceBack ( instanceModel , productType ) ;
300
300
_productManagement . SaveInstance ( productInstance ) ;
@@ -314,7 +314,7 @@ public ActionResult<RecipeModel> GetRecipe(long id)
314
314
return BadRequest ( $ "Id was 0") ;
315
315
var recipe = _productManagement . LoadRecipe ( id ) ;
316
316
if ( recipe == null )
317
- return NotFound ( string . Format ( Strings . RecipeNotFoundException_Message , id ) ) ;
317
+ return NotFound ( new MoryxExceptionResponse { Title = string . Format ( Strings . RecipeNotFoundException_Message , id ) } ) ;
318
318
return ProductConverter . ConvertRecipe ( recipe ) ;
319
319
}
320
320
@@ -330,7 +330,7 @@ public ActionResult<long> SaveRecipe(RecipeModel recipe)
330
330
var type = ReflectionTool . GetPublicClasses < IProductRecipe > ( t => t . Name == recipe . Type )
331
331
. FirstOrDefault ( ) ;
332
332
if ( type == null )
333
- return NotFound ( string . Format ( Strings . RecipeNotFoundException_Message , "null" ) ) ;
333
+ return NotFound ( new MoryxExceptionResponse { Title = string . Format ( Strings . RecipeNotFoundException_Message , "null" ) } ) ;
334
334
var productRecipe = ( IProductRecipe ) Activator . CreateInstance ( type ) ;
335
335
return _productManagement . SaveRecipe ( _productConverter . ConvertRecipeBack ( recipe , productRecipe , null ) ) ;
336
336
}
@@ -362,7 +362,7 @@ public ActionResult<RecipeModel> CreateRecipe(string recipeType)
362
362
// TODO: Use type wrapper
363
363
var type = ReflectionTool . GetPublicClasses < IProductRecipe > ( t => t . Name == recipeType ) . FirstOrDefault ( ) ;
364
364
if ( type == null )
365
- return NotFound ( string . Format ( Strings . RECIPE_TYPE_NOT_FOUND , recipeType ) ) ;
365
+ return NotFound ( new MoryxExceptionResponse { Title = string . Format ( Strings . RECIPE_TYPE_NOT_FOUND , recipeType ) } ) ;
366
366
var recipe = ( IProductRecipe ) Activator . CreateInstance ( type ) ;
367
367
return ProductConverter . ConvertRecipe ( recipe ) ;
368
368
0 commit comments