From 7086341e1b513ee4d35f17c38dcb4a08fe785308 Mon Sep 17 00:00:00 2001 From: Wendell Muntslag Date: Mon, 27 May 2024 13:59:51 +0200 Subject: [PATCH] chore: add rules grid --- .../Components/Layout/MainLayout.razor | 1 + .../Components/Pages/AddCoreRule.razor | 192 ++++++ .../Components/Pages/AddCoreRule.razor.cs | 60 ++ .../Pages/AddCoreRuleCriteriaOperator.razor | 31 + .../AddCoreRuleCriteriaOperator.razor.cs | 84 +++ .../Pages/AddCoreRuleCriterion.razor | 71 +++ .../Pages/AddCoreRuleCriterion.razor.cs | 84 +++ .../Components/Pages/CoreRules.razor | 152 +++++ .../Components/Pages/CoreRules.razor.cs | 192 ++++++ .../Components/Pages/EditCoreRule.razor | 193 ++++++ .../Components/Pages/EditCoreRule.razor.cs | 63 ++ .../Pages/EditCoreRuleCriteriaOperator.razor | 32 + .../EditCoreRuleCriteriaOperator.razor.cs | 88 +++ .../Pages/EditCoreRuleCriterion.razor | 72 +++ .../Pages/EditCoreRuleCriterion.razor.cs | 88 +++ .../Controllers/ExportController.cs | 369 ++++++++++++ .../Controllers/ExportRulesController.cs | 64 ++ .../Data/BlankTriggerAddingConvention.cs | 33 ++ src/iLoan.Rules.Web/Data/RulesContext.cs | 66 +++ src/iLoan.Rules.Web/ILoan.Rules.Web.csproj | 6 +- src/iLoan.Rules.Web/Models/Rules/CoreRule.cs | 66 +++ .../Models/Rules/CoreRuleCriteriaOperator.cs | 22 + .../Models/Rules/CoreRuleCriterion.cs | 31 + src/iLoan.Rules.Web/Program.cs | 17 +- src/iLoan.Rules.Web/Services/RulesService.cs | 560 ++++++++++++++++++ .../appsettings.Development.json | 12 +- src/iLoan.Rules.Web/appsettings.json | 14 +- 27 files changed, 2649 insertions(+), 14 deletions(-) create mode 100644 src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor create mode 100644 src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor.cs create mode 100644 src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor create mode 100644 src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor.cs create mode 100644 src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor create mode 100644 src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor.cs create mode 100644 src/iLoan.Rules.Web/Components/Pages/CoreRules.razor create mode 100644 src/iLoan.Rules.Web/Components/Pages/CoreRules.razor.cs create mode 100644 src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor create mode 100644 src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor.cs create mode 100644 src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor create mode 100644 src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor.cs create mode 100644 src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor create mode 100644 src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor.cs create mode 100644 src/iLoan.Rules.Web/Controllers/ExportController.cs create mode 100644 src/iLoan.Rules.Web/Controllers/ExportRulesController.cs create mode 100644 src/iLoan.Rules.Web/Data/BlankTriggerAddingConvention.cs create mode 100644 src/iLoan.Rules.Web/Data/RulesContext.cs create mode 100644 src/iLoan.Rules.Web/Models/Rules/CoreRule.cs create mode 100644 src/iLoan.Rules.Web/Models/Rules/CoreRuleCriteriaOperator.cs create mode 100644 src/iLoan.Rules.Web/Models/Rules/CoreRuleCriterion.cs create mode 100644 src/iLoan.Rules.Web/Services/RulesService.cs diff --git a/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor b/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor index 6693a79..10f3172 100644 --- a/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor +++ b/src/iLoan.Rules.Web/Components/Layout/MainLayout.razor @@ -25,6 +25,7 @@ + diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor b/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor new file mode 100644 index 0000000..61786fb --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor @@ -0,0 +1,192 @@ +@page "/add-core-rule" + +Add CoreRule + + Cannot save CoreRule + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor.cs b/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor.cs new file mode 100644 index 0000000..020df20 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/AddCoreRule.razor.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Radzen; +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 b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor new file mode 100644 index 0000000..d4e70a1 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor @@ -0,0 +1,31 @@ +@page "/add-core-rule-criteria-operator" + +Add CoreRuleCriteriaOperator + + Cannot save CoreRuleCriteriaOperator + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor.cs b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor.cs new file mode 100644 index 0000000..dbb4cb5 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriteriaOperator.razor.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Radzen; +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 b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor new file mode 100644 index 0000000..bd485f2 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor @@ -0,0 +1,71 @@ +@page "/add-core-rule-criterion" + +Add CoreRuleCriterion + + Cannot save CoreRuleCriterion + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor.cs b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor.cs new file mode 100644 index 0000000..04357f4 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/AddCoreRuleCriterion.razor.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Radzen; +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; } + + protected override async Task OnInitializedAsync() + { + + 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); + } + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor b/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor new file mode 100644 index 0000000..d1275c7 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor @@ -0,0 +1,152 @@ +@page "/core-rules" + +CoreRules + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor.cs b/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor.cs new file mode 100644 index 0000000..f100dd5 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/CoreRules.razor.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Radzen; +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; } + + 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(); + } + + 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} }); + 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 b/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor new file mode 100644 index 0000000..ff2984d --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor @@ -0,0 +1,193 @@ +@page "/edit-core-rule" + +Edit CoreRule + + + Cannot save CoreRule + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor.cs b/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor.cs new file mode 100644 index 0000000..183da57 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/EditCoreRule.razor.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Radzen; +using Radzen.Blazor; + +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 + { + 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/Pages/EditCoreRuleCriteriaOperator.razor b/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor new file mode 100644 index 0000000..2be95b8 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor @@ -0,0 +1,32 @@ +@page "/edit-core-rule-criteria-operator" + +Edit CoreRuleCriteriaOperator + + + Cannot save CoreRuleCriteriaOperator + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor.cs b/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor.cs new file mode 100644 index 0000000..0dff8d6 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriteriaOperator.razor.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Radzen; +using Radzen.Blazor; + +namespace ILoan.Rules.Web.Components.Pages +{ + public partial class EditCoreRuleCriteriaOperator + { + [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() + { + coreRuleCriteriaOperator = await RulesService.GetCoreRuleCriteriaOperatorById(ID); + + 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.UpdateCoreRuleCriteriaOperator(ID, 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/EditCoreRuleCriterion.razor b/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor new file mode 100644 index 0000000..b86a3cf --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor @@ -0,0 +1,72 @@ +@page "/edit-core-rule-criterion" + +Edit CoreRuleCriterion + + + Cannot save CoreRuleCriterion + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor.cs b/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor.cs new file mode 100644 index 0000000..676a4d8 --- /dev/null +++ b/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Radzen; +using Radzen.Blazor; + +namespace ILoan.Rules.Web.Components.Pages +{ + public partial class EditCoreRuleCriterion + { + [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() + { + coreRuleCriterion = await RulesService.GetCoreRuleCriterionById(ID); + + 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.UpdateCoreRuleCriterion(ID, 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); + } + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Controllers/ExportController.cs b/src/iLoan.Rules.Web/Controllers/ExportController.cs new file mode 100644 index 0000000..6d782e7 --- /dev/null +++ b/src/iLoan.Rules.Web/Controllers/ExportController.cs @@ -0,0 +1,369 @@ +using System; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Data; +using System.Globalization; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Mvc; +using System.Text; +using System.IO; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using System.Reflection; +using Microsoft.AspNetCore.Http; + +namespace ILoan.Rules.Web.Controllers +{ + public partial class ExportController : Controller + { + public IQueryable ApplyQuery(IQueryable items, IQueryCollection query = null, bool keyless = false) where T : class + { + if (query != null) + { + if (query.ContainsKey("$expand")) + { + var propertiesToExpand = query["$expand"].ToString().Split(','); + foreach (var p in propertiesToExpand) + { + items = items.Include(p); + } + } + + var filter = query.ContainsKey("$filter") ? query["$filter"].ToString() : null; + if (!string.IsNullOrEmpty(filter)) + { + if(keyless) + { + items = items.ToList().AsQueryable(); + } + items = items.Where(filter); + } + + if (query.ContainsKey("$orderBy")) + { + items = items.OrderBy(query["$orderBy"].ToString()); + } + + if (query.ContainsKey("$skip")) + { + items = items.Skip(int.Parse(query["$skip"].ToString())); + } + + if (query.ContainsKey("$top")) + { + items = items.Take(int.Parse(query["$top"].ToString())); + } + + if (query.ContainsKey("$select")) + { + return items.Select($"new ({query["$select"].ToString()})"); + } + } + + return items; + } + + public FileStreamResult ToCSV(IQueryable query, string fileName = null) + { + var columns = GetProperties(query.ElementType); + + var sb = new StringBuilder(); + + foreach (var item in query) + { + var row = new List(); + + foreach (var column in columns) + { + row.Add($"{GetValue(item, column.Key)}".Trim()); + } + + sb.AppendLine(string.Join(",", row.ToArray())); + } + + + var result = new FileStreamResult(new MemoryStream(UTF8Encoding.Default.GetBytes($"{string.Join(",", columns.Select(c => c.Key))}{System.Environment.NewLine}{sb.ToString()}")), "text/csv"); + result.FileDownloadName = (!string.IsNullOrEmpty(fileName) ? fileName : "Export") + ".csv"; + + return result; + } + + public FileStreamResult ToExcel(IQueryable query, string fileName = null) + { + var columns = GetProperties(query.ElementType); + var stream = new MemoryStream(); + + using (var document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook)) + { + var workbookPart = document.AddWorkbookPart(); + workbookPart.Workbook = new Workbook(); + + var worksheetPart = workbookPart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(); + + var workbookStylesPart = workbookPart.AddNewPart(); + GenerateWorkbookStylesPartContent(workbookStylesPart); + + var sheets = workbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Sheet1" }; + sheets.Append(sheet); + + workbookPart.Workbook.Save(); + + var sheetData = worksheetPart.Worksheet.AppendChild(new SheetData()); + + var headerRow = new Row(); + + foreach (var column in columns) + { + headerRow.Append(new Cell() + { + CellValue = new CellValue(column.Key), + DataType = new EnumValue(CellValues.String) + }); + } + + sheetData.AppendChild(headerRow); + + foreach (var item in query) + { + var row = new Row(); + + foreach (var column in columns) + { + var value = GetValue(item, column.Key); + var stringValue = $"{value}".Trim(); + + var cell = new Cell(); + + var underlyingType = column.Value.IsGenericType && + column.Value.GetGenericTypeDefinition() == typeof(Nullable<>) ? + Nullable.GetUnderlyingType(column.Value) : column.Value; + + var typeCode = Type.GetTypeCode(underlyingType); + + if (typeCode == TypeCode.DateTime) + { + if (!string.IsNullOrWhiteSpace(stringValue)) + { + cell.CellValue = new CellValue() { Text = ((DateTime)value).ToOADate().ToString(System.Globalization.CultureInfo.InvariantCulture) }; + cell.DataType = new EnumValue(CellValues.Number); + cell.StyleIndex = (UInt32Value)1U; + } + } + else if (typeCode == TypeCode.Boolean) + { + cell.CellValue = new CellValue(stringValue.ToLowerInvariant()); + cell.DataType = new EnumValue(CellValues.Boolean); + } + else if (IsNumeric(typeCode)) + { + if (value != null) + { + stringValue = Convert.ToString(value, CultureInfo.InvariantCulture); + } + cell.CellValue = new CellValue(stringValue); + cell.DataType = new EnumValue(CellValues.Number); + } + else + { + cell.CellValue = new CellValue(stringValue); + cell.DataType = new EnumValue(CellValues.String); + } + + row.Append(cell); + } + + sheetData.AppendChild(row); + } + + + workbookPart.Workbook.Save(); + } + + if (stream?.Length > 0) + { + stream.Seek(0, SeekOrigin.Begin); + } + + var result = new FileStreamResult(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + result.FileDownloadName = (!string.IsNullOrEmpty(fileName) ? fileName : "Export") + ".xlsx"; + + return result; + } + + + public static object GetValue(object target, string name) + { + return target.GetType().GetProperty(name).GetValue(target); + } + + public static IEnumerable> GetProperties(Type type) + { + return type.GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Where(p => p.CanRead && IsSimpleType(p.PropertyType)).Select(p => new KeyValuePair(p.Name, p.PropertyType)); + } + + public static bool IsSimpleType(Type type) + { + var underlyingType = type.IsGenericType && + type.GetGenericTypeDefinition() == typeof(Nullable<>) ? + Nullable.GetUnderlyingType(type) : type; + + if(underlyingType == typeof(System.Guid) || underlyingType == typeof(System.DateTimeOffset)) + return true; + +#if NET6_0_OR_GREATER + if(underlyingType == typeof(System.DateOnly) || underlyingType == typeof(System.TimeOnly)) + return true; +#endif + var typeCode = Type.GetTypeCode(underlyingType); + + switch (typeCode) + { + case TypeCode.Boolean: + case TypeCode.Byte: + case TypeCode.Char: + case TypeCode.DateTime: + case TypeCode.Decimal: + case TypeCode.Double: + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + case TypeCode.SByte: + case TypeCode.Single: + case TypeCode.String: + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + return true; + default: + return false; + } + } + + private static bool IsNumeric(TypeCode typeCode) + { + switch (typeCode) + { + case TypeCode.Decimal: + case TypeCode.Double: + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + return true; + default: + return false; + } + } + + private static void GenerateWorkbookStylesPartContent(WorkbookStylesPart workbookStylesPart1) + { + Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac x16r2 xr" } }; + stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); + stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); + stylesheet1.AddNamespaceDeclaration("x16r2", "http://schemas.microsoft.com/office/spreadsheetml/2015/02/main"); + stylesheet1.AddNamespaceDeclaration("xr", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision"); + + Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U, KnownFonts = true }; + + Font font1 = new Font(); + FontSize fontSize1 = new FontSize() { Val = 11D }; + Color color1 = new Color() { Theme = (UInt32Value)1U }; + FontName fontName1 = new FontName() { Val = "Calibri" }; + FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; + FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor }; + + font1.Append(fontSize1); + font1.Append(color1); + font1.Append(fontName1); + font1.Append(fontFamilyNumbering1); + font1.Append(fontScheme1); + + fonts1.Append(font1); + + Fills fills1 = new Fills() { Count = (UInt32Value)2U }; + + Fill fill1 = new Fill(); + PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; + + fill1.Append(patternFill1); + + Fill fill2 = new Fill(); + PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; + + fill2.Append(patternFill2); + + fills1.Append(fill1); + fills1.Append(fill2); + + Borders borders1 = new Borders() { Count = (UInt32Value)1U }; + + Border border1 = new Border(); + LeftBorder leftBorder1 = new LeftBorder(); + RightBorder rightBorder1 = new RightBorder(); + TopBorder topBorder1 = new TopBorder(); + BottomBorder bottomBorder1 = new BottomBorder(); + DiagonalBorder diagonalBorder1 = new DiagonalBorder(); + + border1.Append(leftBorder1); + border1.Append(rightBorder1); + border1.Append(topBorder1); + border1.Append(bottomBorder1); + border1.Append(diagonalBorder1); + + borders1.Append(border1); + + CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U }; + CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; + + cellStyleFormats1.Append(cellFormat1); + + CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)2U }; + CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; + CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)14U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true }; + + cellFormats1.Append(cellFormat2); + cellFormats1.Append(cellFormat3); + + CellStyles cellStyles1 = new CellStyles() { Count = (UInt32Value)1U }; + CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; + + cellStyles1.Append(cellStyle1); + DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U }; + TableStyles tableStyles1 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; + + StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList(); + + StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + + StylesheetExtension stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + + OpenXmlUnknownElement openXmlUnknownElement4 = workbookStylesPart1.CreateUnknownElement(""); + + stylesheetExtension2.Append(openXmlUnknownElement4); + + stylesheetExtensionList1.Append(stylesheetExtension1); + stylesheetExtensionList1.Append(stylesheetExtension2); + + stylesheet1.Append(fonts1); + stylesheet1.Append(fills1); + stylesheet1.Append(borders1); + stylesheet1.Append(cellStyleFormats1); + stylesheet1.Append(cellFormats1); + stylesheet1.Append(cellStyles1); + stylesheet1.Append(differentialFormats1); + stylesheet1.Append(tableStyles1); + stylesheet1.Append(stylesheetExtensionList1); + + workbookStylesPart1.Stylesheet = stylesheet1; + } + } +} diff --git a/src/iLoan.Rules.Web/Controllers/ExportRulesController.cs b/src/iLoan.Rules.Web/Controllers/ExportRulesController.cs new file mode 100644 index 0000000..b0c631d --- /dev/null +++ b/src/iLoan.Rules.Web/Controllers/ExportRulesController.cs @@ -0,0 +1,64 @@ +using System; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using System.Threading.Tasks; + +using ILoan.Rules.Web.Data; + +namespace ILoan.Rules.Web.Controllers +{ + public partial class ExportRulesController : ExportController + { + private readonly RulesContext context; + private readonly RulesService service; + + public ExportRulesController(RulesContext context, RulesService service) + { + this.service = service; + this.context = context; + } + + [HttpGet("/export/Rules/corerulecriteriaoperators/csv")] + [HttpGet("/export/Rules/corerulecriteriaoperators/csv(fileName='{fileName}')")] + public async Task ExportCoreRuleCriteriaOperatorsToCSV(string fileName = null) + { + return ToCSV(ApplyQuery(await service.GetCoreRuleCriteriaOperators(), Request.Query, false), fileName); + } + + [HttpGet("/export/Rules/corerulecriteriaoperators/excel")] + [HttpGet("/export/Rules/corerulecriteriaoperators/excel(fileName='{fileName}')")] + public async Task ExportCoreRuleCriteriaOperatorsToExcel(string fileName = null) + { + return ToExcel(ApplyQuery(await service.GetCoreRuleCriteriaOperators(), Request.Query, false), fileName); + } + + [HttpGet("/export/Rules/corerules/csv")] + [HttpGet("/export/Rules/corerules/csv(fileName='{fileName}')")] + public async Task ExportCoreRulesToCSV(string fileName = null) + { + return ToCSV(ApplyQuery(await service.GetCoreRules(), Request.Query, false), fileName); + } + + [HttpGet("/export/Rules/corerules/excel")] + [HttpGet("/export/Rules/corerules/excel(fileName='{fileName}')")] + public async Task ExportCoreRulesToExcel(string fileName = null) + { + return ToExcel(ApplyQuery(await service.GetCoreRules(), Request.Query, false), fileName); + } + + [HttpGet("/export/Rules/corerulecriteria/csv")] + [HttpGet("/export/Rules/corerulecriteria/csv(fileName='{fileName}')")] + public async Task ExportCoreRuleCriteriaToCSV(string fileName = null) + { + return ToCSV(ApplyQuery(await service.GetCoreRuleCriteria(), Request.Query, false), fileName); + } + + [HttpGet("/export/Rules/corerulecriteria/excel")] + [HttpGet("/export/Rules/corerulecriteria/excel(fileName='{fileName}')")] + public async Task ExportCoreRuleCriteriaToExcel(string fileName = null) + { + return ToExcel(ApplyQuery(await service.GetCoreRuleCriteria(), Request.Query, false), fileName); + } + } +} diff --git a/src/iLoan.Rules.Web/Data/BlankTriggerAddingConvention.cs b/src/iLoan.Rules.Web/Data/BlankTriggerAddingConvention.cs new file mode 100644 index 0000000..f287bef --- /dev/null +++ b/src/iLoan.Rules.Web/Data/BlankTriggerAddingConvention.cs @@ -0,0 +1,33 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +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 new file mode 100644 index 0000000..ee9ad3b --- /dev/null +++ b/src/iLoan.Rules.Web/Data/RulesContext.cs @@ -0,0 +1,66 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using ILoan.Rules.Web.Models.Rules; + +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/ILoan.Rules.Web.csproj b/src/iLoan.Rules.Web/ILoan.Rules.Web.csproj index c0bbf71..57e2a97 100644 --- a/src/iLoan.Rules.Web/ILoan.Rules.Web.csproj +++ b/src/iLoan.Rules.Web/ILoan.Rules.Web.csproj @@ -1,12 +1,14 @@ - CS0168,CS1998,BL9993,CS0649,CS0436,0436 net8.0 enable - + + + + \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Models/Rules/CoreRule.cs b/src/iLoan.Rules.Web/Models/Rules/CoreRule.cs new file mode 100644 index 0000000..2eabece --- /dev/null +++ b/src/iLoan.Rules.Web/Models/Rules/CoreRule.cs @@ -0,0 +1,66 @@ +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 string 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 new file mode 100644 index 0000000..d705642 --- /dev/null +++ b/src/iLoan.Rules.Web/Models/Rules/CoreRuleCriteriaOperator.cs @@ -0,0 +1,22 @@ +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; } + } +} \ 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 new file mode 100644 index 0000000..7c2443b --- /dev/null +++ b/src/iLoan.Rules.Web/Models/Rules/CoreRuleCriterion.cs @@ -0,0 +1,31 @@ +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; } + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/Program.cs b/src/iLoan.Rules.Web/Program.cs index 1e1f7e7..3d69627 100644 --- a/src/iLoan.Rules.Web/Program.cs +++ b/src/iLoan.Rules.Web/Program.cs @@ -1,17 +1,19 @@ using Radzen; using ILoan.Rules.Web.Components; +using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); - // Add services to the container. -builder.Services.AddRazorComponents() - .AddInteractiveServerComponents().AddHubOptions(options => options.MaximumReceiveMessageSize = 10 * 1024 * 1024); - +builder.Services.AddRazorComponents().AddInteractiveServerComponents().AddHubOptions(options => options.MaximumReceiveMessageSize = 10 * 1024 * 1024); builder.Services.AddControllers(); builder.Services.AddRadzenComponents(); builder.Services.AddHttpClient(); +builder.Services.AddScoped(); +builder.Services.AddDbContext(options => +{ + options.UseNpgsql(builder.Configuration.GetConnectionString("RulesConnection")); +}); var app = builder.Build(); - // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -24,8 +26,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/Services/RulesService.cs b/src/iLoan.Rules.Web/Services/RulesService.cs new file mode 100644 index 0000000..6b4178e --- /dev/null +++ b/src/iLoan.Rules.Web/Services/RulesService.cs @@ -0,0 +1,560 @@ +using System; +using System.Data; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Text.Encodings.Web; +using Microsoft.AspNetCore.Components; +using Microsoft.EntityFrameworkCore; +using Radzen; + +using ILoan.Rules.Web.Data; + +namespace ILoan.Rules.Web +{ + public partial class RulesService + { + RulesContext Context + { + get + { + return this.context; + } + } + + private readonly RulesContext context; + private readonly NavigationManager navigationManager; + + public RulesService(RulesContext context, NavigationManager navigationManager) + { + this.context = context; + this.navigationManager = navigationManager; + } + + public void Reset() => Context.ChangeTracker.Entries().Where(e => e.Entity != null).ToList().ForEach(e => e.State = EntityState.Detached); + + public void ApplyQuery(ref IQueryable items, Query query = null) + { + if (query != null) + { + if (!string.IsNullOrEmpty(query.Filter)) + { + if (query.FilterParameters != null) + { + items = items.Where(query.Filter, query.FilterParameters); + } + else + { + items = items.Where(query.Filter); + } + } + + if (!string.IsNullOrEmpty(query.OrderBy)) + { + items = items.OrderBy(query.OrderBy); + } + + if (query.Skip.HasValue) + { + items = items.Skip(query.Skip.Value); + } + + if (query.Top.HasValue) + { + items = items.Take(query.Top.Value); + } + } + } + + + public async Task ExportCoreRuleCriteriaOperatorsToExcel(Query query = null, string fileName = null) + { + navigationManager.NavigateTo(query != null ? query.ToUrl($"export/rules/corerulecriteriaoperators/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/rules/corerulecriteriaoperators/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true); + } + + public async Task ExportCoreRuleCriteriaOperatorsToCSV(Query query = null, string fileName = null) + { + navigationManager.NavigateTo(query != null ? query.ToUrl($"export/rules/corerulecriteriaoperators/csv(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/rules/corerulecriteriaoperators/csv(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true); + } + + partial void OnCoreRuleCriteriaOperatorsRead(ref IQueryable items); + + public async Task> GetCoreRuleCriteriaOperators(Query query = null) + { + var items = Context.CoreRuleCriteriaOperators.AsQueryable(); + + items = items.Include(i => i.CoreRule); + + if (query != null) + { + if (!string.IsNullOrEmpty(query.Expand)) + { + var propertiesToExpand = query.Expand.Split(','); + foreach(var p in propertiesToExpand) + { + items = items.Include(p.Trim()); + } + } + + ApplyQuery(ref items, query); + } + + OnCoreRuleCriteriaOperatorsRead(ref items); + + return await Task.FromResult(items); + } + + partial void OnCoreRuleCriteriaOperatorGet(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator item); + partial void OnGetCoreRuleCriteriaOperatorById(ref IQueryable items); + + + public async Task GetCoreRuleCriteriaOperatorById(int id) + { + var items = Context.CoreRuleCriteriaOperators + .AsNoTracking() + .Where(i => i.ID == id); + + items = items.Include(i => i.CoreRule); + + OnGetCoreRuleCriteriaOperatorById(ref items); + + var itemToReturn = items.FirstOrDefault(); + + OnCoreRuleCriteriaOperatorGet(itemToReturn); + + return await Task.FromResult(itemToReturn); + } + + partial void OnCoreRuleCriteriaOperatorCreated(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator item); + partial void OnAfterCoreRuleCriteriaOperatorCreated(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator item); + + public async Task CreateCoreRuleCriteriaOperator(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator corerulecriteriaoperator) + { + OnCoreRuleCriteriaOperatorCreated(corerulecriteriaoperator); + + var existingItem = Context.CoreRuleCriteriaOperators + .Where(i => i.ID == corerulecriteriaoperator.ID) + .FirstOrDefault(); + + if (existingItem != null) + { + throw new Exception("Item already available"); + } + + try + { + Context.CoreRuleCriteriaOperators.Add(corerulecriteriaoperator); + Context.SaveChanges(); + } + catch + { + Context.Entry(corerulecriteriaoperator).State = EntityState.Detached; + throw; + } + + OnAfterCoreRuleCriteriaOperatorCreated(corerulecriteriaoperator); + + return corerulecriteriaoperator; + } + + public async Task CancelCoreRuleCriteriaOperatorChanges(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator item) + { + var entityToCancel = Context.Entry(item); + if (entityToCancel.State == EntityState.Modified) + { + entityToCancel.CurrentValues.SetValues(entityToCancel.OriginalValues); + entityToCancel.State = EntityState.Unchanged; + } + + return item; + } + + partial void OnCoreRuleCriteriaOperatorUpdated(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator item); + partial void OnAfterCoreRuleCriteriaOperatorUpdated(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator item); + + public async Task UpdateCoreRuleCriteriaOperator(int id, ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator corerulecriteriaoperator) + { + OnCoreRuleCriteriaOperatorUpdated(corerulecriteriaoperator); + + var itemToUpdate = Context.CoreRuleCriteriaOperators + .Where(i => i.ID == corerulecriteriaoperator.ID) + .FirstOrDefault(); + + if (itemToUpdate == null) + { + throw new Exception("Item no longer available"); + } + + var entryToUpdate = Context.Entry(itemToUpdate); + entryToUpdate.CurrentValues.SetValues(corerulecriteriaoperator); + entryToUpdate.State = EntityState.Modified; + + Context.SaveChanges(); + + OnAfterCoreRuleCriteriaOperatorUpdated(corerulecriteriaoperator); + + return corerulecriteriaoperator; + } + + partial void OnCoreRuleCriteriaOperatorDeleted(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator item); + partial void OnAfterCoreRuleCriteriaOperatorDeleted(ILoan.Rules.Web.Models.Rules.CoreRuleCriteriaOperator item); + + public async Task DeleteCoreRuleCriteriaOperator(int id) + { + var itemToDelete = Context.CoreRuleCriteriaOperators + .Where(i => i.ID == id) + .FirstOrDefault(); + + if (itemToDelete == null) + { + throw new Exception("Item no longer available"); + } + + OnCoreRuleCriteriaOperatorDeleted(itemToDelete); + + + Context.CoreRuleCriteriaOperators.Remove(itemToDelete); + + try + { + Context.SaveChanges(); + } + catch + { + Context.Entry(itemToDelete).State = EntityState.Unchanged; + throw; + } + + OnAfterCoreRuleCriteriaOperatorDeleted(itemToDelete); + + return itemToDelete; + } + + public async Task ExportCoreRulesToExcel(Query query = null, string fileName = null) + { + navigationManager.NavigateTo(query != null ? query.ToUrl($"export/rules/corerules/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/rules/corerules/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true); + } + + public async Task ExportCoreRulesToCSV(Query query = null, string fileName = null) + { + navigationManager.NavigateTo(query != null ? query.ToUrl($"export/rules/corerules/csv(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/rules/corerules/csv(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true); + } + + partial void OnCoreRulesRead(ref IQueryable items); + + public async Task> GetCoreRules(Query query = null) + { + var items = Context.CoreRules.AsQueryable(); + + + if (query != null) + { + if (!string.IsNullOrEmpty(query.Expand)) + { + var propertiesToExpand = query.Expand.Split(','); + foreach(var p in propertiesToExpand) + { + items = items.Include(p.Trim()); + } + } + + ApplyQuery(ref items, query); + } + + OnCoreRulesRead(ref items); + + return await Task.FromResult(items); + } + + partial void OnCoreRuleGet(ILoan.Rules.Web.Models.Rules.CoreRule item); + partial void OnGetCoreRuleById(ref IQueryable items); + + + public async Task GetCoreRuleById(int id) + { + var items = Context.CoreRules + .AsNoTracking() + .Where(i => i.ID == id); + + + OnGetCoreRuleById(ref items); + + var itemToReturn = items.FirstOrDefault(); + + OnCoreRuleGet(itemToReturn); + + return await Task.FromResult(itemToReturn); + } + + partial void OnCoreRuleCreated(ILoan.Rules.Web.Models.Rules.CoreRule item); + partial void OnAfterCoreRuleCreated(ILoan.Rules.Web.Models.Rules.CoreRule item); + + public async Task CreateCoreRule(ILoan.Rules.Web.Models.Rules.CoreRule corerule) + { + OnCoreRuleCreated(corerule); + + var existingItem = Context.CoreRules + .Where(i => i.ID == corerule.ID) + .FirstOrDefault(); + + if (existingItem != null) + { + throw new Exception("Item already available"); + } + + try + { + Context.CoreRules.Add(corerule); + Context.SaveChanges(); + } + catch + { + Context.Entry(corerule).State = EntityState.Detached; + throw; + } + + OnAfterCoreRuleCreated(corerule); + + return corerule; + } + + public async Task CancelCoreRuleChanges(ILoan.Rules.Web.Models.Rules.CoreRule item) + { + var entityToCancel = Context.Entry(item); + if (entityToCancel.State == EntityState.Modified) + { + entityToCancel.CurrentValues.SetValues(entityToCancel.OriginalValues); + entityToCancel.State = EntityState.Unchanged; + } + + return item; + } + + partial void OnCoreRuleUpdated(ILoan.Rules.Web.Models.Rules.CoreRule item); + partial void OnAfterCoreRuleUpdated(ILoan.Rules.Web.Models.Rules.CoreRule item); + + public async Task UpdateCoreRule(int id, ILoan.Rules.Web.Models.Rules.CoreRule corerule) + { + OnCoreRuleUpdated(corerule); + + var itemToUpdate = Context.CoreRules + .Where(i => i.ID == corerule.ID) + .FirstOrDefault(); + + if (itemToUpdate == null) + { + throw new Exception("Item no longer available"); + } + + var entryToUpdate = Context.Entry(itemToUpdate); + entryToUpdate.CurrentValues.SetValues(corerule); + entryToUpdate.State = EntityState.Modified; + + Context.SaveChanges(); + + OnAfterCoreRuleUpdated(corerule); + + return corerule; + } + + partial void OnCoreRuleDeleted(ILoan.Rules.Web.Models.Rules.CoreRule item); + partial void OnAfterCoreRuleDeleted(ILoan.Rules.Web.Models.Rules.CoreRule item); + + public async Task DeleteCoreRule(int id) + { + var itemToDelete = Context.CoreRules + .Where(i => i.ID == id) + .Include(i => i.CoreRuleCriteria) + .Include(i => i.CoreRuleCriteriaOperators) + .FirstOrDefault(); + + if (itemToDelete == null) + { + throw new Exception("Item no longer available"); + } + + OnCoreRuleDeleted(itemToDelete); + + + Context.CoreRules.Remove(itemToDelete); + + try + { + Context.SaveChanges(); + } + catch + { + Context.Entry(itemToDelete).State = EntityState.Unchanged; + throw; + } + + OnAfterCoreRuleDeleted(itemToDelete); + + return itemToDelete; + } + + public async Task ExportCoreRuleCriteriaToExcel(Query query = null, string fileName = null) + { + navigationManager.NavigateTo(query != null ? query.ToUrl($"export/rules/corerulecriteria/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/rules/corerulecriteria/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true); + } + + public async Task ExportCoreRuleCriteriaToCSV(Query query = null, string fileName = null) + { + navigationManager.NavigateTo(query != null ? query.ToUrl($"export/rules/corerulecriteria/csv(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/rules/corerulecriteria/csv(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true); + } + + partial void OnCoreRuleCriteriaRead(ref IQueryable items); + + public async Task> GetCoreRuleCriteria(Query query = null) + { + var items = Context.CoreRuleCriteria.AsQueryable(); + + items = items.Include(i => i.CoreRule); + + if (query != null) + { + if (!string.IsNullOrEmpty(query.Expand)) + { + var propertiesToExpand = query.Expand.Split(','); + foreach(var p in propertiesToExpand) + { + items = items.Include(p.Trim()); + } + } + + ApplyQuery(ref items, query); + } + + OnCoreRuleCriteriaRead(ref items); + + return await Task.FromResult(items); + } + + partial void OnCoreRuleCriterionGet(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion item); + partial void OnGetCoreRuleCriterionById(ref IQueryable items); + + + public async Task GetCoreRuleCriterionById(int id) + { + var items = Context.CoreRuleCriteria + .AsNoTracking() + .Where(i => i.ID == id); + + items = items.Include(i => i.CoreRule); + + OnGetCoreRuleCriterionById(ref items); + + var itemToReturn = items.FirstOrDefault(); + + OnCoreRuleCriterionGet(itemToReturn); + + return await Task.FromResult(itemToReturn); + } + + partial void OnCoreRuleCriterionCreated(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion item); + partial void OnAfterCoreRuleCriterionCreated(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion item); + + public async Task CreateCoreRuleCriterion(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion corerulecriterion) + { + OnCoreRuleCriterionCreated(corerulecriterion); + + var existingItem = Context.CoreRuleCriteria + .Where(i => i.ID == corerulecriterion.ID) + .FirstOrDefault(); + + if (existingItem != null) + { + throw new Exception("Item already available"); + } + + try + { + Context.CoreRuleCriteria.Add(corerulecriterion); + Context.SaveChanges(); + } + catch + { + Context.Entry(corerulecriterion).State = EntityState.Detached; + throw; + } + + OnAfterCoreRuleCriterionCreated(corerulecriterion); + + return corerulecriterion; + } + + public async Task CancelCoreRuleCriterionChanges(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion item) + { + var entityToCancel = Context.Entry(item); + if (entityToCancel.State == EntityState.Modified) + { + entityToCancel.CurrentValues.SetValues(entityToCancel.OriginalValues); + entityToCancel.State = EntityState.Unchanged; + } + + return item; + } + + partial void OnCoreRuleCriterionUpdated(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion item); + partial void OnAfterCoreRuleCriterionUpdated(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion item); + + public async Task UpdateCoreRuleCriterion(int id, ILoan.Rules.Web.Models.Rules.CoreRuleCriterion corerulecriterion) + { + OnCoreRuleCriterionUpdated(corerulecriterion); + + var itemToUpdate = Context.CoreRuleCriteria + .Where(i => i.ID == corerulecriterion.ID) + .FirstOrDefault(); + + if (itemToUpdate == null) + { + throw new Exception("Item no longer available"); + } + + var entryToUpdate = Context.Entry(itemToUpdate); + entryToUpdate.CurrentValues.SetValues(corerulecriterion); + entryToUpdate.State = EntityState.Modified; + + Context.SaveChanges(); + + OnAfterCoreRuleCriterionUpdated(corerulecriterion); + + return corerulecriterion; + } + + partial void OnCoreRuleCriterionDeleted(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion item); + partial void OnAfterCoreRuleCriterionDeleted(ILoan.Rules.Web.Models.Rules.CoreRuleCriterion item); + + public async Task DeleteCoreRuleCriterion(int id) + { + var itemToDelete = Context.CoreRuleCriteria + .Where(i => i.ID == id) + .FirstOrDefault(); + + if (itemToDelete == null) + { + throw new Exception("Item no longer available"); + } + + OnCoreRuleCriterionDeleted(itemToDelete); + + + Context.CoreRuleCriteria.Remove(itemToDelete); + + try + { + Context.SaveChanges(); + } + catch + { + Context.Entry(itemToDelete).State = EntityState.Unchanged; + throw; + } + + OnAfterCoreRuleCriterionDeleted(itemToDelete); + + return itemToDelete; + } + } +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/appsettings.Development.json b/src/iLoan.Rules.Web/appsettings.Development.json index 770d3e9..7190799 100644 --- a/src/iLoan.Rules.Web/appsettings.Development.json +++ b/src/iLoan.Rules.Web/appsettings.Development.json @@ -5,5 +5,15 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "ConnectionStrings": { + "RulesConnection": "Host=localhost;User ID=wendell@iloan.nl;Password=8o%2FGjK&A#p^De1;Timeout=30;Port=5432;Database=iloan-dev-rules" + }, + "Databases": { + "Rules": { + "NoPluralize": false, + "UseDatabaseNames": false, + "UseEFNaming": false + } } -} +} \ No newline at end of file diff --git a/src/iLoan.Rules.Web/appsettings.json b/src/iLoan.Rules.Web/appsettings.json index 10f68b8..1e549f8 100644 --- a/src/iLoan.Rules.Web/appsettings.json +++ b/src/iLoan.Rules.Web/appsettings.json @@ -5,5 +5,15 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} + "AllowedHosts": "*", + "ConnectionStrings": { + "RulesConnection": "Host=localhost;User ID=wendell@iloan.nl;Password=8o%2FGjK&A#p^De1;Timeout=30;Port=5432;Database=iloan-dev-rules" + }, + "Databases": { + "Rules": { + "NoPluralize": false, + "UseDatabaseNames": false, + "UseEFNaming": false + } + } +} \ No newline at end of file