Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Harmony.AspNetCore/Harmony.AspNetCore.synproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
<OutputPath>bin\AnyCPU\ReleaseNuget\</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core">
<Version>2.2.5</Version>
</PackageReference>
<PackageReference Include="Synergex.SynergyDE.Build" Version="11.1.1010.2674" />
<PackageReference Include="Synergex.SynergyDE.synrnt" Version="11.1.1010" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Synergex.SynergyDE.synrnt" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
Expand All @@ -50,6 +52,7 @@
<Compile Include="AspNetCoreDebugLogger.dbl" />
<Compile Include="Context\IMultiTenantMiddleware.dbl" />
<Compile Include="MultiTenantProvider.dbl" />
<Compile Include="ValidationHelper.dbl" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HarmonyCore\HarmonyCore.synproj">
Expand Down
31 changes: 31 additions & 0 deletions Harmony.AspNetCore/ValidationHelper.dbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import System
import System.Collections.Generic
import System.Text
import Microsoft.AspNetCore.Mvc
import Microsoft.AspNetCore.Mvc.ModelBinding

namespace Harmony.AspNetCore

public class ValidationHelper

public static method ReturnValidationError, @IActionResult
state, @ModelStateDictionary
proc
data errorText = new List<String>()
data errorPair, @KeyValuePair<string, ModelStateEntry>

foreach errorPair in state
begin
data errorValue, @ModelError
foreach errorValue in errorPair.Value.Errors
begin
errorText.Add(errorValue.ErrorMessage)
end
end

mreturn new BadRequestObjectResult(string.Join(%char(13) + %char(10), errorText))
endmethod

endclass

endnamespace
13 changes: 7 additions & 6 deletions Services.Controllers/CustomerNotesController.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import System.ComponentModel.DataAnnotations
import Harmony.Core.EF.Extensions
import Harmony.Core.Interface
import Harmony.OData
import Harmony.AspNetCore
import Newtonsoft.Json
import Services.Models

Expand Down Expand Up @@ -129,7 +130,7 @@ namespace Services.Controllers

;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Get the next available primary key value
disposable data keyFactory = (@IPrimaryKeyFactory)_ServiceProvider.GetService(^typeof(IPrimaryKeyFactory))
Expand All @@ -144,7 +145,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -166,7 +167,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Ensure that the key values in the URI win over any data that may be in the model object
aCustomerNote.CustomerNumber = aCustomerNumber
Expand Down Expand Up @@ -195,7 +196,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -215,7 +216,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Patch the existing customerNote
try
Expand Down Expand Up @@ -244,7 +245,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand Down
13 changes: 7 additions & 6 deletions Services.Controllers/CustomersController.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import System.ComponentModel.DataAnnotations
import Harmony.Core.EF.Extensions
import Harmony.Core.Interface
import Harmony.OData
import Harmony.AspNetCore
import Newtonsoft.Json
import Services.Models

Expand Down Expand Up @@ -360,7 +361,7 @@ namespace Services.Controllers

;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Get the next available primary key value
disposable data keyFactory = (@IPrimaryKeyFactory)_ServiceProvider.GetService(^typeof(IPrimaryKeyFactory))
Expand All @@ -375,7 +376,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -397,7 +398,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Ensure that the key values in the URI win over any data that may be in the model object
aCustomer.CustomerNumber = aCustomerNumber
Expand Down Expand Up @@ -426,7 +427,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -446,7 +447,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Patch the existing customer
try
Expand Down Expand Up @@ -475,7 +476,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand Down
13 changes: 7 additions & 6 deletions Services.Controllers/ItemsController.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import System.ComponentModel.DataAnnotations
import Harmony.Core.EF.Extensions
import Harmony.Core.Interface
import Harmony.OData
import Harmony.AspNetCore
import Newtonsoft.Json
import Services.Models

Expand Down Expand Up @@ -521,7 +522,7 @@ namespace Services.Controllers

;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Get the next available primary key value
disposable data keyFactory = (@IPrimaryKeyFactory)_ServiceProvider.GetService(^typeof(IPrimaryKeyFactory))
Expand All @@ -536,7 +537,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -558,7 +559,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Ensure that the key values in the URI win over any data that may be in the model object
aItem.ItemNumber = aItemNumber
Expand Down Expand Up @@ -587,7 +588,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -607,7 +608,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Patch the existing item
try
Expand Down Expand Up @@ -636,7 +637,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand Down
13 changes: 7 additions & 6 deletions Services.Controllers/OrderItemsController.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import System.ComponentModel.DataAnnotations
import Harmony.Core.EF.Extensions
import Harmony.Core.Interface
import Harmony.OData
import Harmony.AspNetCore
import Newtonsoft.Json
import Services.Models

Expand Down Expand Up @@ -254,7 +255,7 @@ namespace Services.Controllers

;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Get the next available primary key value
disposable data keyFactory = (@IPrimaryKeyFactory)_ServiceProvider.GetService(^typeof(IPrimaryKeyFactory))
Expand All @@ -269,7 +270,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -294,7 +295,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Ensure that the key values in the URI win over any data that may be in the model object
aOrderItem.OrderNumber = aOrderNumber
Expand Down Expand Up @@ -324,7 +325,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -347,7 +348,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Patch the existing orderItem
try
Expand Down Expand Up @@ -376,7 +377,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand Down
13 changes: 7 additions & 6 deletions Services.Controllers/OrdersController.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import System.ComponentModel.DataAnnotations
import Harmony.Core.EF.Extensions
import Harmony.Core.Interface
import Harmony.OData
import Harmony.AspNetCore
import Newtonsoft.Json
import Services.Models

Expand Down Expand Up @@ -252,7 +253,7 @@ namespace Services.Controllers

;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Get the next available primary key value
disposable data keyFactory = (@IPrimaryKeyFactory)_ServiceProvider.GetService(^typeof(IPrimaryKeyFactory))
Expand All @@ -267,7 +268,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -289,7 +290,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Ensure that the key values in the URI win over any data that may be in the model object
aOrder.OrderNumber = aOrderNumber
Expand Down Expand Up @@ -318,7 +319,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand All @@ -338,7 +339,7 @@ namespace Services.Controllers
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)

;;Patch the existing order
try
Expand Down Expand Up @@ -367,7 +368,7 @@ namespace Services.Controllers
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn BadRequest(ModelState)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry

Expand Down
Loading