chore: manage rules
This commit is contained in:
parent
76cb895f40
commit
a866237dea
@ -9,7 +9,7 @@
|
|||||||
<RadzenLabel Text="Rule Name" Component="RuleName" style="width: 100%" />
|
<RadzenLabel Text="Rule Name" Component="RuleName" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.RuleName" Name="RuleName" />
|
<RadzenTextArea style="display: block; width: 100%" @bind-Value="@coreRule.RuleName" Name="RuleName" />
|
||||||
<RadzenRequiredValidator Component="RuleName" Text="RuleName is required" />
|
<RadzenRequiredValidator Component="RuleName" Text="RuleName is required" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
@ -115,7 +115,7 @@
|
|||||||
<RadzenLabel Text="Dutch Rule Name" Component="DutchRuleName" style="width: 100%" />
|
<RadzenLabel Text="Dutch Rule Name" Component="DutchRuleName" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.DutchRuleName" Name="DutchRuleName" />
|
<RadzenTextArea style="display: block; width: 100%" @bind-Value="@coreRule.DutchRuleName" Name="DutchRuleName" />
|
||||||
<RadzenRequiredValidator Component="DutchRuleName" Text="DutchRuleName is required" />
|
<RadzenRequiredValidator Component="DutchRuleName" Text="DutchRuleName is required" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
@ -156,7 +156,7 @@
|
|||||||
<RadzenLabel Text="Dutch Rule Explanation" Component="DutchRuleExplanation" style="width: 100%" />
|
<RadzenLabel Text="Dutch Rule Explanation" Component="DutchRuleExplanation" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.DutchRuleExplanation" Name="DutchRuleExplanation" />
|
<RadzenTextArea style="display: block; width: 100%" @bind-Value="@coreRule.DutchRuleExplanation" Name="DutchRuleExplanation" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
<RadzenRow style="margin-bottom: 1rem">
|
<RadzenRow style="margin-bottom: 1rem">
|
||||||
@ -177,10 +177,10 @@
|
|||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
<RadzenRow style="margin-bottom: 1rem">
|
<RadzenRow style="margin-bottom: 1rem">
|
||||||
<RadzenColumn SizeMD="3">
|
<RadzenColumn SizeMD="3">
|
||||||
<RadzenLabel Text="update" Component="update" style="width: 100%" />
|
<RadzenLabel Text="Update" Component="Update" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.update" Name="update" />
|
<RadzenNumeric style="display: block; width: 100%" @bind-Value="@coreRule.Update" Name="Update" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn Size="12" SizeMD="6">
|
<RadzenColumn Size="12" SizeMD="6">
|
||||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||||
|
<RadzenButton Icon="build" Text="Generate" Click="@GenerateButtonClick" Variant="Variant.Flat" />
|
||||||
<RadzenButton Icon="add_circle_outline" Text="Add" Click="@AddButtonClick" Variant="Variant.Flat"/>
|
<RadzenButton Icon="add_circle_outline" Text="Add" Click="@AddButtonClick" Variant="Variant.Flat"/>
|
||||||
</RadzenStack>
|
</RadzenStack>
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
|
@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ILoan.Rules.Web.Services;
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
@ -33,6 +34,9 @@ namespace ILoan.Rules.Web.Components.Pages
|
|||||||
[Inject]
|
[Inject]
|
||||||
public RulesService RulesService { get; set; }
|
public RulesService RulesService { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
public RuleFileGeneratorService RuleFileGeneratorService { get; set; }
|
||||||
|
|
||||||
protected IEnumerable<ILoan.Rules.Web.Models.Rules.CoreRule> coreRules;
|
protected IEnumerable<ILoan.Rules.Web.Models.Rules.CoreRule> coreRules;
|
||||||
|
|
||||||
protected RadzenDataGrid<ILoan.Rules.Web.Models.Rules.CoreRule> grid0;
|
protected RadzenDataGrid<ILoan.Rules.Web.Models.Rules.CoreRule> grid0;
|
||||||
@ -47,6 +51,23 @@ namespace ILoan.Rules.Web.Components.Pages
|
|||||||
await grid0.Reload();
|
await grid0.Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execute RuleFileGeneratorService to generate SQL files
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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)
|
protected async Task EditRow(ILoan.Rules.Web.Models.Rules.CoreRule args)
|
||||||
{
|
{
|
||||||
await DialogService.OpenAsync<EditCoreRule>("Edit CoreRule", new Dictionary<string, object> { {"ID", args.ID} });
|
await DialogService.OpenAsync<EditCoreRule>("Edit CoreRule", new Dictionary<string, object> { {"ID", args.ID} });
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<RadzenLabel Text="Rule Name" Component="RuleName" style="width: 100%" />
|
<RadzenLabel Text="Rule Name" Component="RuleName" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.RuleName" Name="RuleName" />
|
<RadzenTextArea style="display: block; width: 100%" @bind-Value="@coreRule.RuleName" Name="RuleName" />
|
||||||
<RadzenRequiredValidator Component="RuleName" Text="RuleName is required" />
|
<RadzenRequiredValidator Component="RuleName" Text="RuleName is required" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
@ -116,7 +116,7 @@
|
|||||||
<RadzenLabel Text="Dutch Rule Name" Component="DutchRuleName" style="width: 100%" />
|
<RadzenLabel Text="Dutch Rule Name" Component="DutchRuleName" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.DutchRuleName" Name="DutchRuleName" />
|
<RadzenTextArea style="display: block; width: 100%" @bind-Value="@coreRule.DutchRuleName" Name="DutchRuleName" />
|
||||||
<RadzenRequiredValidator Component="DutchRuleName" Text="DutchRuleName is required" />
|
<RadzenRequiredValidator Component="DutchRuleName" Text="DutchRuleName is required" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
@ -149,7 +149,7 @@
|
|||||||
<RadzenLabel Text="Rule Explanation" Component="RuleExplanation" style="width: 100%" />
|
<RadzenLabel Text="Rule Explanation" Component="RuleExplanation" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.RuleExplanation" Name="RuleExplanation" />
|
<RadzenTextArea style="display: block; width: 100%" @bind-Value="@coreRule.RuleExplanation" Name="RuleExplanation" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
<RadzenRow style="margin-bottom: 1rem">
|
<RadzenRow style="margin-bottom: 1rem">
|
||||||
@ -157,7 +157,7 @@
|
|||||||
<RadzenLabel Text="Dutch Rule Explanation" Component="DutchRuleExplanation" style="width: 100%" />
|
<RadzenLabel Text="Dutch Rule Explanation" Component="DutchRuleExplanation" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.DutchRuleExplanation" Name="DutchRuleExplanation" />
|
<RadzenTextArea style="display: block; width: 100%" @bind-Value="@coreRule.DutchRuleExplanation" Name="DutchRuleExplanation" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
<RadzenRow style="margin-bottom: 1rem">
|
<RadzenRow style="margin-bottom: 1rem">
|
||||||
@ -178,10 +178,10 @@
|
|||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
<RadzenRow style="margin-bottom: 1rem">
|
<RadzenRow style="margin-bottom: 1rem">
|
||||||
<RadzenColumn SizeMD="3">
|
<RadzenColumn SizeMD="3">
|
||||||
<RadzenLabel Text="update" Component="update" style="width: 100%" />
|
<RadzenLabel Text="update" Component="Update" style="width: 100%" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn SizeMD="9">
|
<RadzenColumn SizeMD="9">
|
||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRule.update" Name="update" />
|
<RadzenNumeric style="display: block; width: 100%" @bind-Value="@coreRule.Update" Name="Update" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.JSInterop;
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
|
using Microsoft.JSInterop;
|
||||||
using Radzen;
|
using Radzen;
|
||||||
using Radzen.Blazor;
|
|
||||||
|
|
||||||
namespace ILoan.Rules.Web.Components.Pages
|
namespace ILoan.Rules.Web.Components.Pages
|
||||||
{
|
{
|
||||||
@ -46,6 +41,7 @@ namespace ILoan.Rules.Web.Components.Pages
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
coreRule.Update += 1;
|
||||||
await RulesService.UpdateCoreRule(ID, coreRule);
|
await RulesService.UpdateCoreRule(ID, coreRule);
|
||||||
DialogService.Close(coreRule);
|
DialogService.Close(coreRule);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,14 @@
|
|||||||
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRuleCriteriaOperator.Operator1" Name="Operator1" />
|
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRuleCriteriaOperator.Operator1" Name="Operator1" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
|
<RadzenRow style="margin-bottom: 1rem">
|
||||||
|
<RadzenColumn SizeMD="3">
|
||||||
|
<RadzenLabel Text="update" Component="Update" style="width: 100%" />
|
||||||
|
</RadzenColumn>
|
||||||
|
<RadzenColumn SizeMD="9">
|
||||||
|
<RadzenNumeric style="display: block; width: 100%" @bind-Value="@coreRuleCriteriaOperator.Update" Name="Update" />
|
||||||
|
</RadzenColumn>
|
||||||
|
</RadzenRow>
|
||||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||||
<RadzenButton ButtonStyle="ButtonStyle.Primary" ButtonType="ButtonType.Submit" Icon="save" Text="Save" Variant="Variant.Flat" />
|
<RadzenButton ButtonStyle="ButtonStyle.Primary" ButtonType="ButtonType.Submit" Icon="save" Text="Save" Variant="Variant.Flat" />
|
||||||
<RadzenButton ButtonStyle="ButtonStyle.Light" Text="Cancel" Variant="Variant.Flat" Click="@CancelButtonClick" />
|
<RadzenButton ButtonStyle="ButtonStyle.Light" Text="Cancel" Variant="Variant.Flat" Click="@CancelButtonClick" />
|
||||||
|
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Components;
|
|||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using Radzen;
|
using Radzen;
|
||||||
using Radzen.Blazor;
|
using Radzen.Blazor;
|
||||||
|
using ILoan.Rules.Web.Models.Rules;
|
||||||
|
|
||||||
namespace ILoan.Rules.Web.Components.Pages
|
namespace ILoan.Rules.Web.Components.Pages
|
||||||
{
|
{
|
||||||
@ -50,6 +51,7 @@ namespace ILoan.Rules.Web.Components.Pages
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
coreRuleCriteriaOperator.Update += 1;
|
||||||
await RulesService.UpdateCoreRuleCriteriaOperator(ID, coreRuleCriteriaOperator);
|
await RulesService.UpdateCoreRuleCriteriaOperator(ID, coreRuleCriteriaOperator);
|
||||||
DialogService.Close(coreRuleCriteriaOperator);
|
DialogService.Close(coreRuleCriteriaOperator);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,14 @@
|
|||||||
<RadzenCheckBox @bind-Value="@coreRuleCriterion.IsThresholdCriterium" Name="IsThresholdCriterium" />
|
<RadzenCheckBox @bind-Value="@coreRuleCriterion.IsThresholdCriterium" Name="IsThresholdCriterium" />
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
|
<RadzenRow style="margin-bottom: 1rem">
|
||||||
|
<RadzenColumn SizeMD="3">
|
||||||
|
<RadzenLabel Text="update" Component="Update" style="width: 100%" />
|
||||||
|
</RadzenColumn>
|
||||||
|
<RadzenColumn SizeMD="9">
|
||||||
|
<RadzenNumeric style="display: block; width: 100%" @bind-Value="@coreRuleCriterion.Update" Name="Update" />
|
||||||
|
</RadzenColumn>
|
||||||
|
</RadzenRow>
|
||||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||||
<RadzenButton ButtonStyle="ButtonStyle.Primary" ButtonType="ButtonType.Submit" Icon="save" Text="Save" Variant="Variant.Flat" />
|
<RadzenButton ButtonStyle="ButtonStyle.Primary" ButtonType="ButtonType.Submit" Icon="save" Text="Save" Variant="Variant.Flat" />
|
||||||
<RadzenButton ButtonStyle="ButtonStyle.Light" Text="Cancel" Variant="Variant.Flat" Click="@CancelButtonClick" />
|
<RadzenButton ButtonStyle="ButtonStyle.Light" Text="Cancel" Variant="Variant.Flat" Click="@CancelButtonClick" />
|
||||||
|
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Components;
|
|||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using Radzen;
|
using Radzen;
|
||||||
using Radzen.Blazor;
|
using Radzen.Blazor;
|
||||||
|
using ILoan.Rules.Web.Models.Rules;
|
||||||
|
|
||||||
namespace ILoan.Rules.Web.Components.Pages
|
namespace ILoan.Rules.Web.Components.Pages
|
||||||
{
|
{
|
||||||
@ -50,6 +51,7 @@ namespace ILoan.Rules.Web.Components.Pages
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
coreRuleCriterion.Update += 1;
|
||||||
await RulesService.UpdateCoreRuleCriterion(ID, coreRuleCriterion);
|
await RulesService.UpdateCoreRuleCriterion(ID, coreRuleCriterion);
|
||||||
DialogService.Close(coreRuleCriterion);
|
DialogService.Close(coreRuleCriterion);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ namespace ILoan.Rules.Web.Models.Rules
|
|||||||
|
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
|
||||||
public string update { get; set; }
|
public int Update { get; set; }
|
||||||
|
|
||||||
public ICollection<CoreRuleCriterion> CoreRuleCriteria { get; set; } = [];
|
public ICollection<CoreRuleCriterion> CoreRuleCriteria { get; set; } = [];
|
||||||
|
|
||||||
|
@ -18,5 +18,8 @@ namespace ILoan.Rules.Web.Models.Rules
|
|||||||
|
|
||||||
[Column("Operator")]
|
[Column("Operator")]
|
||||||
public string Operator1 { get; set; }
|
public string Operator1 { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public int Update { get; set; } = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,5 +27,8 @@ namespace ILoan.Rules.Web.Models.Rules
|
|||||||
public bool? ReturnCount { get; set; }
|
public bool? ReturnCount { get; set; }
|
||||||
|
|
||||||
public bool? IsThresholdCriterium { get; set; }
|
public bool? IsThresholdCriterium { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public int Update { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using Radzen;
|
using Radzen;
|
||||||
using ILoan.Rules.Web.Components;
|
using ILoan.Rules.Web.Components;
|
||||||
|
using ILoan.Rules.Web.Services;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@ -9,6 +10,7 @@ builder.Services.AddControllers();
|
|||||||
builder.Services.AddRadzenComponents();
|
builder.Services.AddRadzenComponents();
|
||||||
builder.Services.AddHttpClient();
|
builder.Services.AddHttpClient();
|
||||||
builder.Services.AddScoped<ILoan.Rules.Web.RulesService>();
|
builder.Services.AddScoped<ILoan.Rules.Web.RulesService>();
|
||||||
|
builder.Services.AddScoped<RuleFileGeneratorService>();
|
||||||
builder.Services.AddDbContext<ILoan.Rules.Web.Data.RulesContext>(options =>
|
builder.Services.AddDbContext<ILoan.Rules.Web.Data.RulesContext>(options =>
|
||||||
{
|
{
|
||||||
options.UseNpgsql(builder.Configuration.GetConnectionString("RulesConnection"));
|
options.UseNpgsql(builder.Configuration.GetConnectionString("RulesConnection"));
|
||||||
|
75
src/iLoan.Rules.Web/Services/RuleFileGeneratorService.cs
Normal file
75
src/iLoan.Rules.Web/Services/RuleFileGeneratorService.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using ILoan.Rules.Web.Data;
|
||||||
|
using ILoan.Rules.Web.Models.Rules;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ILoan.Rules.Web.Services;
|
||||||
|
|
||||||
|
public class RuleFileGeneratorService
|
||||||
|
{
|
||||||
|
private readonly RulesContext _context;
|
||||||
|
private readonly int _startRuleId;
|
||||||
|
private int _startSeq;
|
||||||
|
private readonly string _root;
|
||||||
|
|
||||||
|
public RuleFileGeneratorService(RulesContext context, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
_startRuleId = configuration.GetValue<int>("Parameters:StartRuleId");
|
||||||
|
_startSeq = configuration.GetValue<int>("Parameters:StartSeqNo");
|
||||||
|
_root = configuration.GetValue<string>("Parameters:GeneratorRoot");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task GenerateRuleFilesAsync()
|
||||||
|
{
|
||||||
|
if (!_root.EndsWith("migrations"))
|
||||||
|
{
|
||||||
|
if (Directory.Exists(_root)) Directory.Delete(_root, true);
|
||||||
|
if (!Directory.Exists(_root)) Directory.CreateDirectory(_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
var rules = await _context.CoreRules.Where(rule => rule.ID >= _startRuleId).ToListAsync();
|
||||||
|
|
||||||
|
foreach (var rule in rules.OrderBy(x =>x.ID))
|
||||||
|
{
|
||||||
|
var fileName = $"V2.{_startSeq:000}__{rule.WorkItemId}_Rules_{rule.ID}_{rule.Title}.sql";
|
||||||
|
|
||||||
|
if (rule.Update > 0)
|
||||||
|
{
|
||||||
|
fileName = $"V2.{_startSeq:000}__{rule.WorkItemId}_Rules_{rule.ID}_{rule.Title}_Update({rule.Update}).sql";
|
||||||
|
}
|
||||||
|
|
||||||
|
var sql = GenerateSqlStatement(rule);
|
||||||
|
// Simulate writing to a file (you can replace this with actual file writing)
|
||||||
|
Console.WriteLine($"Generating file: {fileName}");
|
||||||
|
await File.WriteAllTextAsync(Path.Combine(_root, fileName), sql, Encoding.UTF8);
|
||||||
|
_startSeq++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateSqlStatement(CoreRule rule)
|
||||||
|
{
|
||||||
|
return $@"
|
||||||
|
-- SQL statement to insert or update the rule
|
||||||
|
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""
|
||||||
|
) 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)}',
|
||||||
|
'{EscapeSingleQuote(rule.TriggerReason)}', {rule.UseLastRecord?.ToString().ToUpper() ?? "NULL"}, '{EscapeSingleQuote(rule.ApplicantType)}',
|
||||||
|
'{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)}'
|
||||||
|
);
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? EscapeSingleQuote(string value)
|
||||||
|
{
|
||||||
|
return value?.Replace("'", "''");
|
||||||
|
}
|
||||||
|
}
|
@ -15,5 +15,10 @@
|
|||||||
"UseDatabaseNames": false,
|
"UseDatabaseNames": false,
|
||||||
"UseEFNaming": false
|
"UseEFNaming": false
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Parameters": {
|
||||||
|
"GeneratorRoot": "C:\\iloan\\iloan-base-dev\\migrations",
|
||||||
|
"StartSeqNo": 104,
|
||||||
|
"StartRuleId": 480
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user