diff --git a/src/iLoan.Rules.Web/Components/App.razor b/src/iLoan.Rules.Web/Application/App.razor similarity index 100% rename from src/iLoan.Rules.Web/Components/App.razor rename to src/iLoan.Rules.Web/Application/App.razor diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor b/src/iLoan.Rules.Web/Application/EditCoreRule.razor similarity index 98% rename from src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor rename to src/iLoan.Rules.Web/Application/EditCoreRule.razor index e679931..a8d429f 100644 --- a/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor +++ b/src/iLoan.Rules.Web/Application/EditCoreRule.razor @@ -1,10 +1,11 @@ @page "/edit-core-rule" +@using ILoan.Tools.Domain.Entities Edit CoreRule Cannot save CoreRule - + diff --git a/src/iLoan.Rules.Web/Application/EditCoreRule.razor.cs b/src/iLoan.Rules.Web/Application/EditCoreRule.razor.cs new file mode 100644 index 0000000..7893727 --- /dev/null +++ b/src/iLoan.Rules.Web/Application/EditCoreRule.razor.cs @@ -0,0 +1,55 @@ +using ILoan.Tools.Infrastructure.Services; + +namespace ILoan.Tools.Application; + +public partial class EditCoreRule +{ + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected NavigationManager NavigationManager { get; set; } + + [Inject] + protected DialogService DialogService { get; set; } + + [Inject] + protected TooltipService TooltipService { get; set; } + + [Inject] + protected ContextMenuService ContextMenuService { get; set; } + + [Inject] + protected NotificationService NotificationService { get; set; } + [Inject] + public RulesService RulesService { get; set; } + + [Parameter] + public int ID { get; set; } + + protected override async Task OnInitializedAsync() + { + coreRule = await RulesService.GetCoreRuleById(ID); + } + protected bool errorVisible; + protected CoreRule coreRule; + + protected async Task FormSubmit() + { + try + { + coreRule.Update += 1; + await RulesService.UpdateCoreRule(ID, coreRule); + DialogService.Close(coreRule); + } + catch (Exception ex) + { + errorVisible = true; + } + } + + protected async Task CancelButtonClick(MouseEventArgs args) + { + DialogService.Close(null); + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor b/src/iLoan.Rules.Web/Application/Layout/MainLayout.razor similarity index 84% rename from src/iLoan.Rules.Web/Components/Layout/MainLayout.razor rename to src/iLoan.Rules.Web/Application/Layout/MainLayout.razor index 5cde18d..9dfa8a3 100644 --- a/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor +++ b/src/iLoan.Rules.Web/Application/Layout/MainLayout.razor @@ -21,13 +21,13 @@ - + - + diff --git a/src/iLoan.Rules.Web/Application/Layout/MainLayout.razor.cs b/src/iLoan.Rules.Web/Application/Layout/MainLayout.razor.cs new file mode 100644 index 0000000..c1e2b58 --- /dev/null +++ b/src/iLoan.Rules.Web/Application/Layout/MainLayout.razor.cs @@ -0,0 +1,29 @@ +namespace ILoan.Tools.Application.Layout; + +public partial class MainLayout +{ + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected NavigationManager NavigationManager { get; set; } + + [Inject] + protected DialogService DialogService { get; set; } + + [Inject] + protected TooltipService TooltipService { get; set; } + + [Inject] + protected ContextMenuService ContextMenuService { get; set; } + + [Inject] + protected NotificationService NotificationService { get; set; } + + private bool sidebarExpanded = true; + + void SidebarToggleClick() + { + sidebarExpanded = !sidebarExpanded; + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor b/src/iLoan.Rules.Web/Application/Pages/AddCoreRule.razor similarity index 98% rename from src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor rename to src/iLoan.Rules.Web/Application/Pages/AddCoreRule.razor index d95fd70..25a8551 100644 --- a/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor +++ b/src/iLoan.Rules.Web/Application/Pages/AddCoreRule.razor @@ -1,9 +1,10 @@ @page "/add-core-rule" +@using ILoan.Tools.Domain.Entities Add CoreRule Cannot save CoreRule - + diff --git a/src/iLoan.Rules.Web/Application/Pages/AddCoreRule.razor.cs b/src/iLoan.Rules.Web/Application/Pages/AddCoreRule.razor.cs new file mode 100644 index 0000000..c017929 --- /dev/null +++ b/src/iLoan.Rules.Web/Application/Pages/AddCoreRule.razor.cs @@ -0,0 +1,51 @@ +using ILoan.Tools.Infrastructure.Services; + +namespace ILoan.Tools.Application.Pages; + +public partial class AddCoreRule +{ + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected NavigationManager NavigationManager { get; set; } + + [Inject] + protected DialogService DialogService { get; set; } + + [Inject] + protected TooltipService TooltipService { get; set; } + + [Inject] + protected ContextMenuService ContextMenuService { get; set; } + + [Inject] + protected NotificationService NotificationService { get; set; } + [Inject] + public RulesService RulesService { get; set; } + + protected override async Task OnInitializedAsync() + { + coreRule = new CoreRule(); + } + protected bool errorVisible; + protected CoreRule coreRule; + + protected async Task FormSubmit() + { + try + { + await RulesService.CreateCoreRule(coreRule); + DialogService.Close(coreRule); + } + catch (Exception ex) + { + errorVisible = true; + } + } + + protected async Task CancelButtonClick(MouseEventArgs args) + { + DialogService.Close(null); + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor b/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriteriaOperator.razor similarity index 90% rename from src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor rename to src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriteriaOperator.razor index d4e70a1..bc8035b 100644 --- a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor +++ b/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriteriaOperator.razor @@ -3,7 +3,7 @@ Add CoreRuleCriteriaOperator Cannot save CoreRuleCriteriaOperator - + diff --git a/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriteriaOperator.razor.cs b/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriteriaOperator.razor.cs new file mode 100644 index 0000000..6f6f937 --- /dev/null +++ b/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriteriaOperator.razor.cs @@ -0,0 +1,75 @@ +using ILoan.Tools.Infrastructure.Services; + +namespace ILoan.Tools.Application.Pages; + +public partial class AddCoreRuleCriteriaOperator +{ + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected NavigationManager NavigationManager { get; set; } + + [Inject] + protected DialogService DialogService { get; set; } + + [Inject] + protected TooltipService TooltipService { get; set; } + + [Inject] + protected ContextMenuService ContextMenuService { get; set; } + + [Inject] + protected NotificationService NotificationService { get; set; } + [Inject] + public RulesService RulesService { get; set; } + + protected override async Task OnInitializedAsync() + { + + coreRulesForRuleID = await RulesService.GetCoreRules(); + } + protected bool errorVisible; + protected CoreRuleCriteriaOperator coreRuleCriteriaOperator; + + protected IEnumerable coreRulesForRuleID; + + protected async Task FormSubmit() + { + try + { + await RulesService.CreateCoreRuleCriteriaOperator(coreRuleCriteriaOperator); + DialogService.Close(coreRuleCriteriaOperator); + } + catch (Exception ex) + { + errorVisible = true; + } + } + + protected async Task CancelButtonClick(MouseEventArgs args) + { + DialogService.Close(null); + } + + + + + + bool hasRuleIDValue; + + [Parameter] + public int? RuleID { get; set; } + public override async Task SetParametersAsync(ParameterView parameters) + { + coreRuleCriteriaOperator = new CoreRuleCriteriaOperator(); + + hasRuleIDValue = parameters.TryGetValue("RuleID", out var hasRuleIDResult); + + if (hasRuleIDValue) + { + coreRuleCriteriaOperator.RuleID = hasRuleIDResult; + } + await base.SetParametersAsync(parameters); + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor b/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriterion.razor similarity index 96% rename from src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor rename to src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriterion.razor index 5f51c37..50d1efd 100644 --- a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor +++ b/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriterion.razor @@ -3,7 +3,7 @@ Add CoreRuleCriterion Cannot save CoreRuleCriterion - + diff --git a/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriterion.razor.cs b/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriterion.razor.cs new file mode 100644 index 0000000..81b5454 --- /dev/null +++ b/src/iLoan.Rules.Web/Application/Pages/AddCoreRuleCriterion.razor.cs @@ -0,0 +1,85 @@ +using ILoan.Tools.Infrastructure.Services; + +namespace ILoan.Tools.Application.Pages; + +public partial class AddCoreRuleCriterion +{ + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected NavigationManager NavigationManager { get; set; } + + [Inject] + protected DialogService DialogService { get; set; } + + [Inject] + protected TooltipService TooltipService { get; set; } + + [Inject] + protected ContextMenuService ContextMenuService { get; set; } + + [Inject] + protected NotificationService NotificationService { get; set; } + [Inject] + public RulesService RulesService { get; set; } + + public List Properties { get; set; } + public List Comparisons { get; set; } + + protected override async Task OnInitializedAsync() + { + Properties = RulesService.GetProperties(); + Comparisons = RulesService.GetComparisons(); + + coreRulesForRuleID = await RulesService.GetCoreRules(); + } + protected bool errorVisible; + protected CoreRuleCriterion coreRuleCriterion; + + protected IEnumerable coreRulesForRuleID; + + protected async Task FormSubmit() + { + try + { + await RulesService.CreateCoreRuleCriterion(coreRuleCriterion); + DialogService.Close(coreRuleCriterion); + } + catch (Exception ex) + { + errorVisible = true; + } + } + + protected async Task CancelButtonClick(MouseEventArgs args) + { + DialogService.Close(null); + } + + + + + + bool hasRuleIDValue; + + [Parameter] + public int? RuleID { get; set; } + public override async Task SetParametersAsync(ParameterView parameters) + { + coreRuleCriterion = new CoreRuleCriterion(); + + hasRuleIDValue = parameters.TryGetValue("RuleID", out var hasRuleIDResult); + + if (hasRuleIDValue) + { + coreRuleCriterion.RuleID = hasRuleIDResult; + } + await base.SetParametersAsync(parameters); + } + + void OnChange(dynamic args) + { + coreRuleCriterion.Property = args; + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor b/src/iLoan.Rules.Web/Application/Pages/CoreRules.razor similarity index 99% rename from src/iLoan.Rules.Web/Components/Pages/CoreRules.razor rename to src/iLoan.Rules.Web/Application/Pages/CoreRules.razor index 31471a5..45c968f 100644 --- a/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor +++ b/src/iLoan.Rules.Web/Application/Pages/CoreRules.razor @@ -1,4 +1,5 @@ @page "/" +@using ILoan.Tools.Domain.Entities CoreRules @@ -20,7 +21,7 @@ - + diff --git a/src/iLoan.Rules.Web/Application/Pages/CoreRules.razor.cs b/src/iLoan.Rules.Web/Application/Pages/CoreRules.razor.cs new file mode 100644 index 0000000..b4e7465 --- /dev/null +++ b/src/iLoan.Rules.Web/Application/Pages/CoreRules.razor.cs @@ -0,0 +1,207 @@ +using ILoan.Tools.Infrastructure.Services; + +namespace ILoan.Tools.Application.Pages; + +public partial class CoreRules +{ + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected NavigationManager NavigationManager { get; set; } + + [Inject] + protected DialogService DialogService { get; set; } + + [Inject] + protected TooltipService TooltipService { get; set; } + + [Inject] + protected ContextMenuService ContextMenuService { get; set; } + + [Inject] + protected NotificationService NotificationService { get; set; } + + [Inject] + public RulesService RulesService { get; set; } + + [Inject] + public RuleFileGeneratorService RuleFileGeneratorService { get; set; } + + protected IEnumerable coreRules; + + protected RadzenDataGrid grid0; + protected override async Task OnInitializedAsync() + { + coreRules = await RulesService.GetCoreRules(); + } + + protected async Task AddButtonClick(MouseEventArgs args) + { + await DialogService.OpenAsync("Add CoreRule", null); + await grid0.Reload(); + } + + /// + /// Execute RuleFileGeneratorService to generate SQL files + /// + /// + /// + protected async Task GenerateButtonClick() + { + await RuleFileGeneratorService.GenerateRuleFilesAsync(); + NotificationService.Notify(new NotificationMessage + { + Severity = NotificationSeverity.Success, + Summary = $"Success", + Detail = $"Rule files generated successfully", + + }); + } + + protected async Task EditRow(CoreRule args) + { + await DialogService.OpenAsync("Edit CoreRule", new Dictionary { {"ID", args.ID} }); + } + + protected async Task GridDeleteButtonClick(MouseEventArgs args, CoreRule coreRule) + { + try + { + if (await DialogService.Confirm("Are you sure you want to delete this record?") == true) + { + var deleteResult = await RulesService.DeleteCoreRule(coreRule.ID); + + if (deleteResult != null) + { + await grid0.Reload(); + } + } + } + catch (Exception ex) + { + NotificationService.Notify(new NotificationMessage + { + Severity = NotificationSeverity.Error, + Summary = $"Error", + Detail = $"Unable to delete CoreRule" + }); + } + } + + protected CoreRule coreRuleChild; + protected async Task GetChildData(CoreRule args) + { + coreRuleChild = args; + var CoreRuleCriteriaResult = await RulesService.GetCoreRuleCriteria(new Query { Filter = $@"i => i.RuleID == {args.ID}", Expand = "CoreRule" }); + if (CoreRuleCriteriaResult != null) + { + args.CoreRuleCriteria = CoreRuleCriteriaResult.ToList(); + } + var CoreRuleCriteriaOperatorsResult = await RulesService.GetCoreRuleCriteriaOperators(new Query { Filter = $@"i => i.RuleID == {args.ID}", Expand = "CoreRule" }); + if (CoreRuleCriteriaOperatorsResult != null) + { + args.CoreRuleCriteriaOperators = CoreRuleCriteriaOperatorsResult.ToList(); + } + } + protected CoreRuleCriterion coreRuleCriterionCoreRuleCriteria; + + protected IEnumerable coreRulesForRuleIDCoreRuleCriteria; + + protected RadzenDataGrid CoreRuleCriteriaDataGrid; + + protected async Task CoreRuleCriteriaAddButtonClick(MouseEventArgs args, CoreRule data) + { + + var dialogResult = await DialogService.OpenAsync("Add CoreRuleCriteria", new Dictionary { {"RuleID" , data.ID} }, new DialogOptions + { + Width = "70%" + }); + + await GetChildData(data); + await CoreRuleCriteriaDataGrid.Reload(); + + } + + protected async Task CoreRuleCriteriaRowSelect(CoreRuleCriterion args, CoreRule data) + { + var dialogResult = await DialogService.OpenAsync("Edit CoreRuleCriteria", new Dictionary { {"ID", args.ID} }); + await GetChildData(data); + await CoreRuleCriteriaDataGrid.Reload(); + } + + protected async Task CoreRuleCriteriaDeleteButtonClick(MouseEventArgs args, CoreRuleCriterion coreRuleCriterion) + { + try + { + if (await DialogService.Confirm("Are you sure you want to delete this record?") == true) + { + var deleteResult = await RulesService.DeleteCoreRuleCriterion(coreRuleCriterion.ID); + + await GetChildData(coreRuleChild); + + if (deleteResult != null) + { + await CoreRuleCriteriaDataGrid.Reload(); + } + } + } + catch (System.Exception ex) + { + NotificationService.Notify(new NotificationMessage + { + Severity = NotificationSeverity.Error, + Summary = $"Error", + Detail = $"Unable to delete CoreRuleCriterion" + }); + } + } + protected CoreRuleCriteriaOperator coreRuleCriteriaOperatorCoreRuleCriteriaOperators; + + protected IEnumerable coreRulesForRuleIDCoreRuleCriteriaOperators; + + protected RadzenDataGrid CoreRuleCriteriaOperatorsDataGrid; + + protected async Task CoreRuleCriteriaOperatorsAddButtonClick(MouseEventArgs args, CoreRule data) + { + + var dialogResult = await DialogService.OpenAsync("Add CoreRuleCriteriaOperators", new Dictionary { {"RuleID" , data.ID} }); + await GetChildData(data); + await CoreRuleCriteriaOperatorsDataGrid.Reload(); + + } + + protected async Task CoreRuleCriteriaOperatorsRowSelect(CoreRuleCriteriaOperator args, CoreRule data) + { + var dialogResult = await DialogService.OpenAsync("Edit CoreRuleCriteriaOperators", new Dictionary { {"ID", args.ID} }); + await GetChildData(data); + await CoreRuleCriteriaOperatorsDataGrid.Reload(); + } + + protected async Task CoreRuleCriteriaOperatorsDeleteButtonClick(MouseEventArgs args, CoreRuleCriteriaOperator coreRuleCriteriaOperator) + { + try + { + if (await DialogService.Confirm("Are you sure you want to delete this record?") == true) + { + var deleteResult = await RulesService.DeleteCoreRuleCriteriaOperator(coreRuleCriteriaOperator.ID); + + await GetChildData(coreRuleChild); + + if (deleteResult != null) + { + await CoreRuleCriteriaOperatorsDataGrid.Reload(); + } + } + } + catch (System.Exception ex) + { + NotificationService.Notify(new NotificationMessage + { + Severity = NotificationSeverity.Error, + Summary = $"Error", + Detail = $"Unable to delete CoreRuleCriteriaOperator" + }); + } + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor b/src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriteriaOperator.razor similarity index 92% rename from src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor rename to src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriteriaOperator.razor index c65c274..e400461 100644 --- a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor +++ b/src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriteriaOperator.razor @@ -4,7 +4,7 @@ Cannot save CoreRuleCriteriaOperator - + diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor.cs b/src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriteriaOperator.razor.cs similarity index 78% rename from src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor.cs rename to src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriteriaOperator.razor.cs index 43b09c2..88c0391 100644 --- a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor.cs +++ b/src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriteriaOperator.razor.cs @@ -1,13 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.JSInterop; -using Microsoft.AspNetCore.Components.Web; -using Radzen.Blazor; -using ILoan.Rules.Web.Services; +using ILoan.Tools.Infrastructure.Services; -namespace ILoan.Rules.Web.Components.Pages +namespace ILoan.Tools.Application.Pages { public partial class EditCoreRuleCriteriaOperator { @@ -41,9 +34,9 @@ namespace ILoan.Rules.Web.Components.Pages coreRulesForRuleID = await RulesService.GetCoreRules(); } protected bool errorVisible; - protected ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator coreRuleCriteriaOperator; + protected CoreRuleCriteriaOperator coreRuleCriteriaOperator; - protected IEnumerable coreRulesForRuleID; + protected IEnumerable coreRulesForRuleID; protected async Task FormSubmit() { @@ -74,7 +67,7 @@ namespace ILoan.Rules.Web.Components.Pages public int? RuleID { get; set; } public override async Task SetParametersAsync(ParameterView parameters) { - coreRuleCriteriaOperator = new ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator(); + coreRuleCriteriaOperator = new CoreRuleCriteriaOperator(); hasRuleIDValue = parameters.TryGetValue("RuleID", out var hasRuleIDResult); diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor b/src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriterion.razor similarity index 96% rename from src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor rename to src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriterion.razor index 97cd684..bed9b41 100644 --- a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor +++ b/src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriterion.razor @@ -4,7 +4,7 @@ Cannot save CoreRuleCriterion - + diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor.cs b/src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriterion.razor.cs similarity index 80% rename from src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor.cs rename to src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriterion.razor.cs index f7e0890..dac3f95 100644 --- a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor.cs +++ b/src/iLoan.Rules.Web/Application/Pages/EditCoreRuleCriterion.razor.cs @@ -1,13 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.JSInterop; -using Microsoft.AspNetCore.Components.Web; -using Radzen.Blazor; -using ILoan.Rules.Web.Services; +using ILoan.Tools.Infrastructure.Services; -namespace ILoan.Rules.Web.Components.Pages +namespace ILoan.Tools.Application.Pages { public partial class EditCoreRuleCriterion { @@ -47,9 +40,9 @@ namespace ILoan.Rules.Web.Components.Pages coreRulesForRuleID = await RulesService.GetCoreRules(); } protected bool errorVisible; - protected ILoan.Rules.Web.Models.Rules.CoreRuleCriterion coreRuleCriterion; + protected CoreRuleCriterion coreRuleCriterion; - protected IEnumerable coreRulesForRuleID; + protected IEnumerable coreRulesForRuleID; protected async Task FormSubmit() { @@ -80,7 +73,7 @@ namespace ILoan.Rules.Web.Components.Pages public int? RuleID { get; set; } public override async Task SetParametersAsync(ParameterView parameters) { - coreRuleCriterion = new ILoan.Rules.Web.Models.Rules.CoreRuleCriterion(); + coreRuleCriterion = new CoreRuleCriterion(); hasRuleIDValue = parameters.TryGetValue("RuleID", out var hasRuleIDResult); diff --git a/src/iLoan.Rules.Web/Components/Routes.razor b/src/iLoan.Rules.Web/Application/Routes.razor similarity index 100% rename from src/iLoan.Rules.Web/Components/Routes.razor rename to src/iLoan.Rules.Web/Application/Routes.razor diff --git a/src/iLoan.Rules.Web/Components/_Imports.razor b/src/iLoan.Rules.Web/Application/_Imports.razor similarity index 81% rename from src/iLoan.Rules.Web/Components/_Imports.razor rename to src/iLoan.Rules.Web/Application/_Imports.razor index 362cf11..a2d9b6e 100644 --- a/src/iLoan.Rules.Web/Components/_Imports.razor +++ b/src/iLoan.Rules.Web/Application/_Imports.razor @@ -9,6 +9,6 @@ @using Radzen @using Radzen.Blazor @using static Microsoft.AspNetCore.Components.Web.RenderMode -@using ILoan.Rules.Web -@using ILoan.Rules.Web.Components -@using ILoan.Rules.Web.Components.Layout +@using ILoan.Tools +@using ILoan.Tools.Application +@using ILoan.Tools.Application.Layout diff --git a/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor.cs b/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor.cs deleted file mode 100644 index a6ae771..0000000 --- a/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Net.Http; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.AspNetCore.Components.Forms; -using Microsoft.AspNetCore.Components.Routing; -using Microsoft.AspNetCore.Components.Web; -using Microsoft.AspNetCore.Components.Web.Virtualization; -using Microsoft.JSInterop; -using Radzen.Blazor; - -namespace ILoan.Rules.Web.Components.Layout -{ - public partial class MainLayout - { - [Inject] - protected IJSRuntime JSRuntime { get; set; } - - [Inject] - protected NavigationManager NavigationManager { get; set; } - - [Inject] - protected DialogService DialogService { get; set; } - - [Inject] - protected TooltipService TooltipService { get; set; } - - [Inject] - protected ContextMenuService ContextMenuService { get; set; } - - [Inject] - protected NotificationService NotificationService { get; set; } - - private bool sidebarExpanded = true; - - void SidebarToggleClick() - { - sidebarExpanded = !sidebarExpanded; - } - } -} diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor.cs b/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor.cs deleted file mode 100644 index 6414ad0..0000000 --- a/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ILoan.Rules.Web.Services; -using Microsoft.JSInterop; -using Microsoft.AspNetCore.Components.Web; -using Radzen.Blazor; - -namespace ILoan.Rules.Web.Components.Pages -{ - public partial class AddCoreRule - { - [Inject] - protected IJSRuntime JSRuntime { get; set; } - - [Inject] - protected NavigationManager NavigationManager { get; set; } - - [Inject] - protected DialogService DialogService { get; set; } - - [Inject] - protected TooltipService TooltipService { get; set; } - - [Inject] - protected ContextMenuService ContextMenuService { get; set; } - - [Inject] - protected NotificationService NotificationService { get; set; } - [Inject] - public RulesService RulesService { get; set; } - - protected override async Task OnInitializedAsync() - { - coreRule = new ILoan.Rules.Web.Models.Rules.CoreRule(); - } - protected bool errorVisible; - protected ILoan.Rules.Web.Models.Rules.CoreRule coreRule; - - protected async Task FormSubmit() - { - try - { - await RulesService.CreateCoreRule(coreRule); - DialogService.Close(coreRule); - } - catch (Exception ex) - { - errorVisible = true; - } - } - - protected async Task CancelButtonClick(MouseEventArgs args) - { - DialogService.Close(null); - } - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor.cs b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor.cs deleted file mode 100644 index cbe9d18..0000000 --- a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ILoan.Rules.Web.Services; -using Microsoft.JSInterop; -using Microsoft.AspNetCore.Components.Web; -using Radzen.Blazor; - -namespace ILoan.Rules.Web.Components.Pages -{ - public partial class AddCoreRuleCriteriaOperator - { - [Inject] - protected IJSRuntime JSRuntime { get; set; } - - [Inject] - protected NavigationManager NavigationManager { get; set; } - - [Inject] - protected DialogService DialogService { get; set; } - - [Inject] - protected TooltipService TooltipService { get; set; } - - [Inject] - protected ContextMenuService ContextMenuService { get; set; } - - [Inject] - protected NotificationService NotificationService { get; set; } - [Inject] - public RulesService RulesService { get; set; } - - protected override async Task OnInitializedAsync() - { - - coreRulesForRuleID = await RulesService.GetCoreRules(); - } - protected bool errorVisible; - protected ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator coreRuleCriteriaOperator; - - protected IEnumerable coreRulesForRuleID; - - protected async Task FormSubmit() - { - try - { - await RulesService.CreateCoreRuleCriteriaOperator(coreRuleCriteriaOperator); - DialogService.Close(coreRuleCriteriaOperator); - } - catch (Exception ex) - { - errorVisible = true; - } - } - - protected async Task CancelButtonClick(MouseEventArgs args) - { - DialogService.Close(null); - } - - - - - - bool hasRuleIDValue; - - [Parameter] - public int? RuleID { get; set; } - public override async Task SetParametersAsync(ParameterView parameters) - { - coreRuleCriteriaOperator = new ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator(); - - hasRuleIDValue = parameters.TryGetValue("RuleID", out var hasRuleIDResult); - - if (hasRuleIDValue) - { - coreRuleCriteriaOperator.RuleID = hasRuleIDResult; - } - await base.SetParametersAsync(parameters); - } - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor.cs b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor.cs deleted file mode 100644 index 3b2b1f6..0000000 --- a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using DocumentFormat.OpenXml.CustomProperties; -using ILoan.Rules.Web.Services; -using Microsoft.JSInterop; -using Microsoft.AspNetCore.Components.Web; -using Radzen.Blazor; - -namespace ILoan.Rules.Web.Components.Pages -{ - public partial class AddCoreRuleCriterion - { - [Inject] - protected IJSRuntime JSRuntime { get; set; } - - [Inject] - protected NavigationManager NavigationManager { get; set; } - - [Inject] - protected DialogService DialogService { get; set; } - - [Inject] - protected TooltipService TooltipService { get; set; } - - [Inject] - protected ContextMenuService ContextMenuService { get; set; } - - [Inject] - protected NotificationService NotificationService { get; set; } - [Inject] - public RulesService RulesService { get; set; } - - public List Properties { get; set; } - public List Comparisons { get; set; } - - protected override async Task OnInitializedAsync() - { - Properties = RulesService.GetProperties(); - Comparisons = RulesService.GetComparisons(); - - coreRulesForRuleID = await RulesService.GetCoreRules(); - } - protected bool errorVisible; - protected ILoan.Rules.Web.Models.Rules.CoreRuleCriterion coreRuleCriterion; - - protected IEnumerable coreRulesForRuleID; - - protected async Task FormSubmit() - { - try - { - await RulesService.CreateCoreRuleCriterion(coreRuleCriterion); - DialogService.Close(coreRuleCriterion); - } - catch (Exception ex) - { - errorVisible = true; - } - } - - protected async Task CancelButtonClick(MouseEventArgs args) - { - DialogService.Close(null); - } - - - - - - bool hasRuleIDValue; - - [Parameter] - public int? RuleID { get; set; } - public override async Task SetParametersAsync(ParameterView parameters) - { - coreRuleCriterion = new ILoan.Rules.Web.Models.Rules.CoreRuleCriterion(); - - hasRuleIDValue = parameters.TryGetValue("RuleID", out var hasRuleIDResult); - - if (hasRuleIDValue) - { - coreRuleCriterion.RuleID = hasRuleIDResult; - } - await base.SetParametersAsync(parameters); - } - - void OnChange(dynamic args) - { - coreRuleCriterion.Property = args; - } - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor.cs b/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor.cs deleted file mode 100644 index 24201ef..0000000 --- a/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor.cs +++ /dev/null @@ -1,215 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ILoan.Rules.Web.Services; -using Microsoft.JSInterop; -using Microsoft.AspNetCore.Components.Web; -using Radzen.Blazor; - -namespace ILoan.Rules.Web.Components.Pages -{ - public partial class CoreRules - { - [Inject] - protected IJSRuntime JSRuntime { get; set; } - - [Inject] - protected NavigationManager NavigationManager { get; set; } - - [Inject] - protected DialogService DialogService { get; set; } - - [Inject] - protected TooltipService TooltipService { get; set; } - - [Inject] - protected ContextMenuService ContextMenuService { get; set; } - - [Inject] - protected NotificationService NotificationService { get; set; } - - [Inject] - public RulesService RulesService { get; set; } - - [Inject] - public RuleFileGeneratorService RuleFileGeneratorService { get; set; } - - protected IEnumerable coreRules; - - protected RadzenDataGrid grid0; - protected override async Task OnInitializedAsync() - { - coreRules = await RulesService.GetCoreRules(); - } - - protected async Task AddButtonClick(MouseEventArgs args) - { - await DialogService.OpenAsync("Add CoreRule", null); - await grid0.Reload(); - } - - /// - /// Execute RuleFileGeneratorService to generate SQL files - /// - /// - /// - protected async Task GenerateButtonClick() - { - await RuleFileGeneratorService.GenerateRuleFilesAsync(); - NotificationService.Notify(new NotificationMessage - { - Severity = NotificationSeverity.Success, - Summary = $"Success", - Detail = $"Rule files generated successfully", - - }); - } - - protected async Task EditRow(ILoan.Rules.Web.Models.Rules.CoreRule args) - { - await DialogService.OpenAsync("Edit CoreRule", new Dictionary { {"ID", args.ID} }); - } - - protected async Task GridDeleteButtonClick(MouseEventArgs args, ILoan.Rules.Web.Models.Rules.CoreRule coreRule) - { - try - { - if (await DialogService.Confirm("Are you sure you want to delete this record?") == true) - { - var deleteResult = await RulesService.DeleteCoreRule(coreRule.ID); - - if (deleteResult != null) - { - await grid0.Reload(); - } - } - } - catch (Exception ex) - { - NotificationService.Notify(new NotificationMessage - { - Severity = NotificationSeverity.Error, - Summary = $"Error", - Detail = $"Unable to delete CoreRule" - }); - } - } - - protected ILoan.Rules.Web.Models.Rules.CoreRule coreRuleChild; - protected async Task GetChildData(ILoan.Rules.Web.Models.Rules.CoreRule args) - { - coreRuleChild = args; - var CoreRuleCriteriaResult = await RulesService.GetCoreRuleCriteria(new Query { Filter = $@"i => i.RuleID == {args.ID}", Expand = "CoreRule" }); - if (CoreRuleCriteriaResult != null) - { - args.CoreRuleCriteria = CoreRuleCriteriaResult.ToList(); - } - var CoreRuleCriteriaOperatorsResult = await RulesService.GetCoreRuleCriteriaOperators(new Query { Filter = $@"i => i.RuleID == {args.ID}", Expand = "CoreRule" }); - if (CoreRuleCriteriaOperatorsResult != null) - { - args.CoreRuleCriteriaOperators = CoreRuleCriteriaOperatorsResult.ToList(); - } - } - protected ILoan.Rules.Web.Models.Rules.CoreRuleCriterion coreRuleCriterionCoreRuleCriteria; - - protected IEnumerable coreRulesForRuleIDCoreRuleCriteria; - - protected RadzenDataGrid CoreRuleCriteriaDataGrid; - - protected async Task CoreRuleCriteriaAddButtonClick(MouseEventArgs args, ILoan.Rules.Web.Models.Rules.CoreRule data) - { - - var dialogResult = await DialogService.OpenAsync("Add CoreRuleCriteria", new Dictionary { {"RuleID" , data.ID} }, new DialogOptions - { - Width = "70%" - }); - - await GetChildData(data); - await CoreRuleCriteriaDataGrid.Reload(); - - } - - protected async Task CoreRuleCriteriaRowSelect(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion args, ILoan.Rules.Web.Models.Rules.CoreRule data) - { - var dialogResult = await DialogService.OpenAsync("Edit CoreRuleCriteria", new Dictionary { {"ID", args.ID} }); - await GetChildData(data); - await CoreRuleCriteriaDataGrid.Reload(); - } - - protected async Task CoreRuleCriteriaDeleteButtonClick(MouseEventArgs args, ILoan.Rules.Web.Models.Rules.CoreRuleCriterion coreRuleCriterion) - { - try - { - if (await DialogService.Confirm("Are you sure you want to delete this record?") == true) - { - var deleteResult = await RulesService.DeleteCoreRuleCriterion(coreRuleCriterion.ID); - - await GetChildData(coreRuleChild); - - if (deleteResult != null) - { - await CoreRuleCriteriaDataGrid.Reload(); - } - } - } - catch (System.Exception ex) - { - NotificationService.Notify(new NotificationMessage - { - Severity = NotificationSeverity.Error, - Summary = $"Error", - Detail = $"Unable to delete CoreRuleCriterion" - }); - } - } - protected ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator coreRuleCriteriaOperatorCoreRuleCriteriaOperators; - - protected IEnumerable coreRulesForRuleIDCoreRuleCriteriaOperators; - - protected RadzenDataGrid CoreRuleCriteriaOperatorsDataGrid; - - protected async Task CoreRuleCriteriaOperatorsAddButtonClick(MouseEventArgs args, ILoan.Rules.Web.Models.Rules.CoreRule data) - { - - var dialogResult = await DialogService.OpenAsync("Add CoreRuleCriteriaOperators", new Dictionary { {"RuleID" , data.ID} }); - await GetChildData(data); - await CoreRuleCriteriaOperatorsDataGrid.Reload(); - - } - - protected async Task CoreRuleCriteriaOperatorsRowSelect(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator args, ILoan.Rules.Web.Models.Rules.CoreRule data) - { - var dialogResult = await DialogService.OpenAsync("Edit CoreRuleCriteriaOperators", new Dictionary { {"ID", args.ID} }); - await GetChildData(data); - await CoreRuleCriteriaOperatorsDataGrid.Reload(); - } - - protected async Task CoreRuleCriteriaOperatorsDeleteButtonClick(MouseEventArgs args, ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator coreRuleCriteriaOperator) - { - try - { - if (await DialogService.Confirm("Are you sure you want to delete this record?") == true) - { - var deleteResult = await RulesService.DeleteCoreRuleCriteriaOperator(coreRuleCriteriaOperator.ID); - - await GetChildData(coreRuleChild); - - if (deleteResult != null) - { - await CoreRuleCriteriaOperatorsDataGrid.Reload(); - } - } - } - catch (System.Exception ex) - { - NotificationService.Notify(new NotificationMessage - { - Severity = NotificationSeverity.Error, - Summary = $"Error", - Detail = $"Unable to delete CoreRuleCriteriaOperator" - }); - } - } - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor.cs b/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor.cs deleted file mode 100644 index 9d15dbe..0000000 --- a/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor.cs +++ /dev/null @@ -1,58 +0,0 @@ -using ILoan.Rules.Web.Services; -using Microsoft.AspNetCore.Components.Web; -using Microsoft.JSInterop; - -namespace ILoan.Rules.Web.Components.Pages -{ - public partial class EditCoreRule - { - [Inject] - protected IJSRuntime JSRuntime { get; set; } - - [Inject] - protected NavigationManager NavigationManager { get; set; } - - [Inject] - protected DialogService DialogService { get; set; } - - [Inject] - protected TooltipService TooltipService { get; set; } - - [Inject] - protected ContextMenuService ContextMenuService { get; set; } - - [Inject] - protected NotificationService NotificationService { get; set; } - [Inject] - public RulesService RulesService { get; set; } - - [Parameter] - public int ID { get; set; } - - protected override async Task OnInitializedAsync() - { - coreRule = await RulesService.GetCoreRuleById(ID); - } - protected bool errorVisible; - protected ILoan.Rules.Web.Models.Rules.CoreRule coreRule; - - protected async Task FormSubmit() - { - try - { - coreRule.Update += 1; - await RulesService.UpdateCoreRule(ID, coreRule); - DialogService.Close(coreRule); - } - catch (Exception ex) - { - errorVisible = true; - } - } - - protected async Task CancelButtonClick(MouseEventArgs args) - { - DialogService.Close(null); - } - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Data/BlankTriggerAddingConvention.cs b/src/iLoan.Rules.Web/Data/BlankTriggerAddingConvention.cs deleted file mode 100644 index e04dda1..0000000 --- a/src/iLoan.Rules.Web/Data/BlankTriggerAddingConvention.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; - -namespace ILoan.Rules.Web.Data -{ - public class BlankTriggerAddingConvention : Microsoft.EntityFrameworkCore.Metadata.Conventions.IModelFinalizingConvention - { - public virtual void ProcessModelFinalizing( - Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionModelBuilder modelBuilder, - Microsoft.EntityFrameworkCore.Metadata.Conventions.IConventionContext context) - { - foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) - { - var table = Microsoft.EntityFrameworkCore.Metadata.StoreObjectIdentifier.Create(entityType, Microsoft.EntityFrameworkCore.Metadata.StoreObjectType.Table); - if (table != null - && entityType.GetDeclaredTriggers().All(t => t.GetDatabaseName(table.Value) == null)) - { - entityType.Builder.HasTrigger(table.Value.Name + "_Trigger"); - } - - foreach (var fragment in entityType.GetMappingFragments(Microsoft.EntityFrameworkCore.Metadata.StoreObjectType.Table)) - { - if (entityType.GetDeclaredTriggers().All(t => t.GetDatabaseName(fragment.StoreObject) == null)) - { - entityType.Builder.HasTrigger(fragment.StoreObject.Name + "_Trigger"); - } - } - } - } - } -} diff --git a/src/iLoan.Rules.Web/Data/RulesContext.cs b/src/iLoan.Rules.Web/Data/RulesContext.cs deleted file mode 100644 index a6292df..0000000 --- a/src/iLoan.Rules.Web/Data/RulesContext.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; - -namespace ILoan.Rules.Web.Data -{ - public partial class RulesContext : DbContext - { - public RulesContext() - { - } - - public RulesContext(DbContextOptions options) : base(options) - { - } - - partial void OnModelBuilding(ModelBuilder builder); - - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); - - builder.Entity() - .HasOne(i => i.CoreRule) - .WithMany(i => i.CoreRuleCriteriaOperators) - .HasForeignKey(i => i.RuleID) - .HasPrincipalKey(i => i.ID); - - builder.Entity() - .HasOne(i => i.CoreRule) - .WithMany(i => i.CoreRuleCriteria) - .HasForeignKey(i => i.RuleID) - .HasPrincipalKey(i => i.ID); - - builder.Entity() - .Property(p => p.UseLastRecord) - .HasDefaultValueSql(@"true"); - - builder.Entity() - .Property(p => p.ValueIsProperty) - .HasDefaultValueSql(@"false"); - - builder.Entity() - .Property(p => p.ReturnCount) - .HasDefaultValueSql(@"false"); - - builder.Entity() - .Property(p => p.IsThresholdCriterium) - .HasDefaultValueSql(@"false"); - this.OnModelBuilding(builder); - } - - public DbSet CoreRuleCriteriaOperators { get; set; } - - public DbSet CoreRules { get; set; } - - public DbSet CoreRuleCriteria { get; set; } - - protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) - { - configurationBuilder.Conventions.Add(_ => new BlankTriggerAddingConvention()); - } - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Domain/Entities/CoreRule.cs b/src/iLoan.Rules.Web/Domain/Entities/CoreRule.cs new file mode 100644 index 0000000..d516fdb --- /dev/null +++ b/src/iLoan.Rules.Web/Domain/Entities/CoreRule.cs @@ -0,0 +1,62 @@ +namespace ILoan.Tools.Domain.Entities; + +[Table("Core_Rules", Schema = "core")] +public partial class CoreRule +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ID { get; set; } + + [Required] + public string RuleName { get; set; } + + [Required] + public string Source { get; set; } + + public decimal? DefaultThreshold { get; set; } + + public bool Blocked { get; set; } + + public bool TriggersManualReview { get; set; } + + public string SuggestedResolution { get; set; } + + public string TriggerReason { get; set; } + + public bool? UseLastRecord { get; set; } + + public string ApplicantType { get; set; } + + public string FilterOnClickthrough { get; set; } + + public string RunBeforeStatus { get; set; } + + public string DisplaySection { get; set; } + + public string WarningField { get; set; } + + [Required] + public string DutchRuleName { get; set; } + + public string DutchTriggerReason { get; set; } + + public string DutchSuggestedResolution { get; set; } + + public string DutchFilterOnClickthrough { get; set; } + + public string RuleExplanation { get; set; } + + public string DutchRuleExplanation { get; set; } + + public int? WorkItemId { get; set; } + + public string Title { get; set; } + + public int Update { get; set; } + + public string Scope { get; set; } + + public ICollection CoreRuleCriteria { get; set; } = []; + + public ICollection CoreRuleCriteriaOperators { get; set; } = []; +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Domain/Entities/CoreRuleCriteriaOperator.cs b/src/iLoan.Rules.Web/Domain/Entities/CoreRuleCriteriaOperator.cs new file mode 100644 index 0000000..e02eda9 --- /dev/null +++ b/src/iLoan.Rules.Web/Domain/Entities/CoreRuleCriteriaOperator.cs @@ -0,0 +1,19 @@ +namespace ILoan.Tools.Domain.Entities; + +[Table("Core_RuleCriteriaOperator", Schema = "core")] +public partial class CoreRuleCriteriaOperator +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ID { get; set; } + + public int? RuleID { get; set; } + + public CoreRule CoreRule { get; set; } + + [Column("Operator")] + public string Operator1 { get; set; } + + + public int Update { get; set; } = 0; +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Domain/Entities/CoreRuleCriterion.cs b/src/iLoan.Rules.Web/Domain/Entities/CoreRuleCriterion.cs new file mode 100644 index 0000000..b82999f --- /dev/null +++ b/src/iLoan.Rules.Web/Domain/Entities/CoreRuleCriterion.cs @@ -0,0 +1,28 @@ +namespace ILoan.Tools.Domain.Entities; + +[Table("Core_RuleCriteria", Schema = "core")] +public partial class CoreRuleCriterion +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ID { get; set; } + + public int? RuleID { get; set; } + + public CoreRule CoreRule { get; set; } + + public string Property { get; set; } + + public string Comparison { get; set; } + + public string Value { get; set; } + + public bool? ValueIsProperty { get; set; } + + public bool? ReturnCount { get; set; } + + public bool? IsThresholdCriterium { get; set; } + + + public int Update { get; set; } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Models/Enums/RuleComparison.cs b/src/iLoan.Rules.Web/Domain/Enums/RuleComparison.cs similarity index 93% rename from src/iLoan.Rules.Web/Models/Enums/RuleComparison.cs rename to src/iLoan.Rules.Web/Domain/Enums/RuleComparison.cs index 9808f88..5e8d02a 100644 --- a/src/iLoan.Rules.Web/Models/Enums/RuleComparison.cs +++ b/src/iLoan.Rules.Web/Domain/Enums/RuleComparison.cs @@ -1,7 +1,4 @@ -using System.ComponentModel.DataAnnotations; -using System.ComponentModel; - -namespace ILoan.Rules.Web.Models.Enums; +namespace ILoan.Tools.Domain.Enums; /// /// The comparison to apply to the rule value. diff --git a/src/iLoan.Rules.Web/Domain/RulesContext.cs b/src/iLoan.Rules.Web/Domain/RulesContext.cs new file mode 100644 index 0000000..f1ef72f --- /dev/null +++ b/src/iLoan.Rules.Web/Domain/RulesContext.cs @@ -0,0 +1,59 @@ +namespace ILoan.Tools.Domain; + +public partial class RulesContext : DbContext +{ + public RulesContext() + { + } + + public RulesContext(DbContextOptions options) : base(options) + { + } + + partial void OnModelBuilding(ModelBuilder builder); + + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + + builder.Entity() + .HasOne(i => i.CoreRule) + .WithMany(i => i.CoreRuleCriteriaOperators) + .HasForeignKey(i => i.RuleID) + .HasPrincipalKey(i => i.ID); + + builder.Entity() + .HasOne(i => i.CoreRule) + .WithMany(i => i.CoreRuleCriteria) + .HasForeignKey(i => i.RuleID) + .HasPrincipalKey(i => i.ID); + + builder.Entity() + .Property(p => p.UseLastRecord) + .HasDefaultValueSql(@"true"); + + builder.Entity() + .Property(p => p.ValueIsProperty) + .HasDefaultValueSql(@"false"); + + builder.Entity() + .Property(p => p.ReturnCount) + .HasDefaultValueSql(@"false"); + + builder.Entity() + .Property(p => p.IsThresholdCriterium) + .HasDefaultValueSql(@"false"); + this.OnModelBuilding(builder); + } + + public DbSet CoreRuleCriteriaOperators { get; set; } + + public DbSet CoreRules { get; set; } + + public DbSet CoreRuleCriteria { get; set; } + + protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) + { + configurationBuilder.Conventions.Add(_ => new BlankTriggerAddingConvention()); + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Domain/Triggers/BlankTriggerAddingConvention.cs b/src/iLoan.Rules.Web/Domain/Triggers/BlankTriggerAddingConvention.cs new file mode 100644 index 0000000..c5a0419 --- /dev/null +++ b/src/iLoan.Rules.Web/Domain/Triggers/BlankTriggerAddingConvention.cs @@ -0,0 +1,27 @@ +namespace ILoan.Tools.Domain.Triggers; + +public class BlankTriggerAddingConvention : Microsoft.EntityFrameworkCore.Metadata.Conventions.IModelFinalizingConvention +{ + public virtual void ProcessModelFinalizing( + Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionModelBuilder modelBuilder, + Microsoft.EntityFrameworkCore.Metadata.Conventions.IConventionContext context) + { + foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) + { + var table = Microsoft.EntityFrameworkCore.Metadata.StoreObjectIdentifier.Create(entityType, Microsoft.EntityFrameworkCore.Metadata.StoreObjectType.Table); + if (table != null + && entityType.GetDeclaredTriggers().All(t => t.GetDatabaseName(table.Value) == null)) + { + entityType.Builder.HasTrigger(table.Value.Name + "_Trigger"); + } + + foreach (var fragment in entityType.GetMappingFragments(Microsoft.EntityFrameworkCore.Metadata.StoreObjectType.Table)) + { + if (entityType.GetDeclaredTriggers().All(t => t.GetDatabaseName(fragment.StoreObject) == null)) + { + entityType.Builder.HasTrigger(fragment.StoreObject.Name + "_Trigger"); + } + } + } + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/GlobalUsings.cs b/src/iLoan.Rules.Web/GlobalUsings.cs new file mode 100644 index 0000000..3971c19 --- /dev/null +++ b/src/iLoan.Rules.Web/GlobalUsings.cs @@ -0,0 +1,19 @@ +// Global using directives + +global using ILoan.Tools.Domain; +global using ILoan.Tools.Domain.Entities; +global using ILoan.Tools.Domain.Enums; +global using ILoan.Tools.Infrastructure.Services; +global using Microsoft.AspNetCore.Components; +global using Microsoft.AspNetCore.Components.Web; +global using Microsoft.EntityFrameworkCore; +global using Microsoft.JSInterop; +global using Radzen; +global using Radzen.Blazor; +global using System.ComponentModel; +global using System.ComponentModel.DataAnnotations; +global using System.ComponentModel.DataAnnotations.Schema; +global using System.Linq.Dynamic.Core; +global using System.Text.Encodings.Web; +global using ILoan.Tools.Domain.Triggers; +global using EnumExtensions = ILoan.Tools.Infrastructure.Extensions.EnumExtensions; \ No newline at end of file diff --git a/src/iLoan.Rules.Web/ILoan.Rules.Web.sln b/src/iLoan.Rules.Web/ILoan.Rules.Web.sln index 2f42491..7dafe3c 100644 --- a/src/iLoan.Rules.Web/ILoan.Rules.Web.sln +++ b/src/iLoan.Rules.Web/ILoan.Rules.Web.sln @@ -2,8 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.0.0 MinimumVisualStudioVersion = 17.0.0.0 - -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILoan.Rules.Web", "ILoan.Rules.Web.csproj", "{E9962792-F259-417D-9699-6283FE80DB7C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILoan.Tools", "ILoan.Tools.csproj", "{E9962792-F259-417D-9699-6283FE80DB7C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -22,4 +21,4 @@ Global GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5931232A-DB88-407E-9DB0-2437600E6ED6} EndGlobalSection -EndGlobal \ No newline at end of file +EndGlobal diff --git a/src/iLoan.Rules.Web/ILoan.Rules.Web.csproj b/src/iLoan.Rules.Web/ILoan.Tools.csproj similarity index 100% rename from src/iLoan.Rules.Web/ILoan.Rules.Web.csproj rename to src/iLoan.Rules.Web/ILoan.Tools.csproj diff --git a/src/iLoan.Rules.Web/Extensions/EnumExtensions.cs b/src/iLoan.Rules.Web/Infrastructure/Extensions/EnumExtensions.cs similarity index 84% rename from src/iLoan.Rules.Web/Extensions/EnumExtensions.cs rename to src/iLoan.Rules.Web/Infrastructure/Extensions/EnumExtensions.cs index 7de1e7c..a54119e 100644 --- a/src/iLoan.Rules.Web/Extensions/EnumExtensions.cs +++ b/src/iLoan.Rules.Web/Infrastructure/Extensions/EnumExtensions.cs @@ -1,4 +1,4 @@ -namespace ILoan.Rules.Web.Extensions; +namespace ILoan.Tools.Infrastructure.Extensions; public static class EnumExtensions { diff --git a/src/iLoan.Rules.Web/Services/RuleFileGeneratorService.cs b/src/iLoan.Rules.Web/Infrastructure/Services/RuleFileGeneratorService.cs similarity index 94% rename from src/iLoan.Rules.Web/Services/RuleFileGeneratorService.cs rename to src/iLoan.Rules.Web/Infrastructure/Services/RuleFileGeneratorService.cs index 30849a3..a163cbb 100644 --- a/src/iLoan.Rules.Web/Services/RuleFileGeneratorService.cs +++ b/src/iLoan.Rules.Web/Infrastructure/Services/RuleFileGeneratorService.cs @@ -1,12 +1,13 @@ using System.Text; -namespace ILoan.Rules.Web.Services; +namespace ILoan.Tools.Infrastructure.Services; public class RuleFileGeneratorService(RulesContext context, IConfiguration configuration) { private readonly int _startRuleId = configuration.GetValue("Parameters:StartRuleId"); private int _startSeq = configuration.GetValue("Parameters:StartSeqNo"); private readonly string _root = configuration.GetValue("Parameters:GeneratorRoot"); + private readonly string _workitem = configuration.GetValue("Parameters:Workitem"); public async Task GenerateRuleFilesAsync() { @@ -22,7 +23,7 @@ public class RuleFileGeneratorService(RulesContext context, IConfiguration confi .Where(rule => rule.ID >= _startRuleId) .ToListAsync(); - foreach (var rule in rules.Where(r => r.ID is >= 511 and <= 513).OrderBy(x => x.ID)) + foreach (var rule in rules.Where(r => _workitem.Contains(r.WorkItemId.ToString())).OrderBy(x => x.ID)) { var fileName = $"V2.{_startSeq:000}__{rule.WorkItemId}_Rules_{rule.ID}_{rule.Title}.sql"; @@ -50,7 +51,7 @@ INSERT INTO core.""Core_Rules"" ( ""ID"", ""RuleName"", ""Source"", ""DefaultThreshold"", ""Blocked"", ""TriggersManualReview"", ""SuggestedResolution"", ""TriggerReason"", ""UseLastRecord"", ""ApplicantType"", ""FilterOnClickthrough"", ""RunBeforeStatus"", ""DisplaySection"", ""WarningField"", ""DutchRuleName"", ""DutchTriggerReason"", - ""DutchSuggestedResolution"", ""DutchFilterOnClickthrough"", ""RuleExplanation"", ""DutchRuleExplanation"" + ""DutchSuggestedResolution"", ""DutchFilterOnClickthrough"", ""RuleExplanation"", ""DutchRuleExplanation"", ""Scope"" ) OVERRIDING SYSTEM VALUE VALUES ( {rule.ID}, '{EscapeSingleQuote(rule.RuleName)}', '{EscapeSingleQuote(rule.Source)}', {rule.DefaultThreshold?.ToString() ?? "NULL"}, {rule.Blocked.ToString().ToUpper()}, {rule.TriggersManualReview.ToString().ToUpper()}, '{EscapeSingleQuote(rule.SuggestedResolution)}', @@ -58,7 +59,7 @@ INSERT INTO core.""Core_Rules"" ( '{EscapeSingleQuote(rule.FilterOnClickthrough)}', '{EscapeSingleQuote(rule.RunBeforeStatus)}', '{EscapeSingleQuote(rule.DisplaySection)}', '{EscapeSingleQuote(rule.WarningField)}', '{EscapeSingleQuote(rule.DutchRuleName)}', '{EscapeSingleQuote(rule.DutchTriggerReason)}', '{EscapeSingleQuote(rule.DutchSuggestedResolution)}', '{EscapeSingleQuote(rule.DutchFilterOnClickthrough)}', - '{EscapeSingleQuote(rule.RuleExplanation)}', '{EscapeSingleQuote(rule.DutchRuleExplanation)}' + '{EscapeSingleQuote(rule.RuleExplanation)}', '{EscapeSingleQuote(rule.DutchRuleExplanation)}', '{EscapeSingleQuote(rule.Scope)}' ); "); @@ -111,7 +112,8 @@ SET ""DutchSuggestedResolution"" = '{EscapeSingleQuote(rule.DutchSuggestedResolution)}', ""DutchFilterOnClickthrough"" = '{EscapeSingleQuote(rule.DutchFilterOnClickthrough)}', ""RuleExplanation"" = '{EscapeSingleQuote(rule.RuleExplanation)}', - ""DutchRuleExplanation"" = '{EscapeSingleQuote(rule.DutchRuleExplanation)}' + ""DutchRuleExplanation"" = '{EscapeSingleQuote(rule.DutchRuleExplanation)}', + ""Scope"" = '{EscapeSingleQuote(rule.Scope)}' WHERE ""ID"" = {rule.ID}; "); diff --git a/src/iLoan.Rules.Web/Services/RulesService.cs b/src/iLoan.Rules.Web/Infrastructure/Services/RulesService.cs similarity index 99% rename from src/iLoan.Rules.Web/Services/RulesService.cs rename to src/iLoan.Rules.Web/Infrastructure/Services/RulesService.cs index 948d945..0f59f37 100644 --- a/src/iLoan.Rules.Web/Services/RulesService.cs +++ b/src/iLoan.Rules.Web/Infrastructure/Services/RulesService.cs @@ -1,4 +1,4 @@ -namespace ILoan.Rules.Web.Services; +namespace ILoan.Tools.Infrastructure.Services; public partial class RulesService(IDbContextFactory factory, NavigationManager navigationManager) { @@ -193,7 +193,7 @@ public partial class RulesService(IDbContextFactory factory, Navig public async Task> GetCoreRules(Query query = null) { var context = await factory.CreateDbContextAsync(); - var items = context.CoreRules.OrderBy(r=>r.ID).AsQueryable(); + var items = context.CoreRules.OrderBy(r => r.ID).AsQueryable(); if (query != null) diff --git a/src/iLoan.Rules.Web/Models/Rules/CoreRule.cs b/src/iLoan.Rules.Web/Models/Rules/CoreRule.cs deleted file mode 100644 index 44d312e..0000000 --- a/src/iLoan.Rules.Web/Models/Rules/CoreRule.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace ILoan.Rules.Web.Models.Rules -{ - [Table("Core_Rules", Schema = "core")] - public partial class CoreRule - { - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int ID { get; set; } - - [Required] - public string RuleName { get; set; } - - [Required] - public string Source { get; set; } - - public decimal? DefaultThreshold { get; set; } - - public bool Blocked { get; set; } - - public bool TriggersManualReview { get; set; } - - public string SuggestedResolution { get; set; } - - public string TriggerReason { get; set; } - - public bool? UseLastRecord { get; set; } - - public string ApplicantType { get; set; } - - public string FilterOnClickthrough { get; set; } - - public string RunBeforeStatus { get; set; } - - public string DisplaySection { get; set; } - - public string WarningField { get; set; } - - [Required] - public string DutchRuleName { get; set; } - - public string DutchTriggerReason { get; set; } - - public string DutchSuggestedResolution { get; set; } - - public string DutchFilterOnClickthrough { get; set; } - - public string RuleExplanation { get; set; } - - public string DutchRuleExplanation { get; set; } - - public decimal? WorkItemId { get; set; } - - public string Title { get; set; } - - public int Update { get; set; } - - public ICollection CoreRuleCriteria { get; set; } = []; - - public ICollection CoreRuleCriteriaOperators { get; set; } = []; - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Models/Rules/CoreRuleCriteriaOperator.cs b/src/iLoan.Rules.Web/Models/Rules/CoreRuleCriteriaOperator.cs deleted file mode 100644 index dcc84d8..0000000 --- a/src/iLoan.Rules.Web/Models/Rules/CoreRuleCriteriaOperator.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace ILoan.Rules.Web.Models.Rules -{ - [Table("Core_RuleCriteriaOperator", Schema = "core")] - public partial class CoreRuleCriteriaOperator - { - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int ID { get; set; } - - public int? RuleID { get; set; } - - public CoreRule CoreRule { get; set; } - - [Column("Operator")] - public string Operator1 { get; set; } - - - public int Update { get; set; } = 0; - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Models/Rules/CoreRuleCriterion.cs b/src/iLoan.Rules.Web/Models/Rules/CoreRuleCriterion.cs deleted file mode 100644 index 58a289f..0000000 --- a/src/iLoan.Rules.Web/Models/Rules/CoreRuleCriterion.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace ILoan.Rules.Web.Models.Rules -{ - [Table("Core_RuleCriteria", Schema = "core")] - public partial class CoreRuleCriterion - { - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int ID { get; set; } - - public int? RuleID { get; set; } - - public CoreRule CoreRule { get; set; } - - public string Property { get; set; } - - public string Comparison { get; set; } - - public string Value { get; set; } - - public bool? ValueIsProperty { get; set; } - - public bool? ReturnCount { get; set; } - - public bool? IsThresholdCriterium { get; set; } - - - public int Update { get; set; } - } -} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Program.cs b/src/iLoan.Rules.Web/Program.cs index f75bd98..4b1f7ed 100644 --- a/src/iLoan.Rules.Web/Program.cs +++ b/src/iLoan.Rules.Web/Program.cs @@ -1,6 +1,3 @@ -using ILoan.Rules.Web.Components; -using ILoan.Rules.Web.Services; - var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorComponents().AddInteractiveServerComponents().AddHubOptions(options => options.MaximumReceiveMessageSize = 10 * 1024 * 1024); @@ -9,7 +6,7 @@ builder.Services.AddRadzenComponents(); builder.Services.AddHttpClient(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddDbContextFactory(options => +builder.Services.AddDbContextFactory(options => { options.UseNpgsql(builder.Configuration.GetConnectionString("RulesConnection")); }); @@ -26,5 +23,5 @@ app.UseHttpsRedirection(); app.MapControllers(); app.UseStaticFiles(); app.UseAntiforgery(); -app.MapRazorComponents().AddInteractiveServerRenderMode(); +app.MapRazorComponents().AddInteractiveServerRenderMode(); app.Run(); \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Properties/launchSettings.json b/src/iLoan.Rules.Web/Properties/launchSettings.json index 087c894..a9637bb 100644 --- a/src/iLoan.Rules.Web/Properties/launchSettings.json +++ b/src/iLoan.Rules.Web/Properties/launchSettings.json @@ -8,7 +8,7 @@ } }, "profiles": { - "ILoan.Rules.Web": { + "ILoan.Tools": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, diff --git a/src/iLoan.Rules.Web/Usings.cs b/src/iLoan.Rules.Web/Usings.cs deleted file mode 100644 index 8f1fc69..0000000 --- a/src/iLoan.Rules.Web/Usings.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Global using directives - -global using ILoan.Rules.Web.Data; -global using ILoan.Rules.Web.Extensions; -global using ILoan.Rules.Web.Models.Enums; -global using ILoan.Rules.Web.Models.Rules; -global using Microsoft.AspNetCore.Components; -global using Microsoft.EntityFrameworkCore; -global using Radzen; -global using System.Linq.Dynamic.Core; -global using System.Text.Encodings.Web; diff --git a/src/iLoan.Rules.Web/appsettings.json b/src/iLoan.Rules.Web/appsettings.json index c217931..451eb44 100644 --- a/src/iLoan.Rules.Web/appsettings.json +++ b/src/iLoan.Rules.Web/appsettings.json @@ -18,7 +18,8 @@ }, "Parameters": { "GeneratorRoot": "C:\\iloan\\iloan-base-dev\\migrations", - "StartSeqNo": 137, - "StartRuleId": 480 + "StartSeqNo": 156, + "StartRuleId": 480, + "Workitem": "3262" } } \ No newline at end of file