Iloan.Rules/src/iLoan.Rules.Web/Components/Pages/EditCoreRuleCriterion.razor.cs
2024-05-28 10:23:17 +02:00

96 lines
2.7 KiB
C#

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;
using ILoan.Rules.Web.Models.Rules;
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; }
public List<string> Properties { get; set; }
public List<string> Comparisons { get; set; }
protected override async Task OnInitializedAsync()
{
Properties = RulesService.GetProperties();
Comparisons = RulesService.GetComparisons();
coreRuleCriterion = await RulesService.GetCoreRuleCriterionById(ID);
coreRulesForRuleID = await RulesService.GetCoreRules();
}
protected bool errorVisible;
protected ILoan.Rules.Web.Models.Rules.CoreRuleCriterion coreRuleCriterion;
protected IEnumerable<ILoan.Rules.Web.Models.Rules.CoreRule> coreRulesForRuleID;
protected async Task FormSubmit()
{
try
{
coreRuleCriterion.Update += 1;
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<int?>("RuleID", out var hasRuleIDResult);
if (hasRuleIDValue)
{
coreRuleCriterion.RuleID = hasRuleIDResult;
}
await base.SetParametersAsync(parameters);
}
}
}