btcpayserver/BTCPayServer/Forms/FormComponentProviders.cs
Nicolas Dorier 1b672a1ace
Allow multi-step settings in custodian (#4838)
* Allow multi-step settings in custodian

* Fix CustodianAccount.Name not saved

* Reuse TradeQuantity for SimulateTrade

* TradeQuantityJsonConverter accepts numerics

* Fix build
2023-04-04 14:48:29 +09:00

34 lines
1.1 KiB
C#

using System.Collections.Generic;
using BTCPayServer.Abstractions.Form;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace BTCPayServer.Forms;
public class FormComponentProviders
{
private readonly IEnumerable<IFormComponentProvider> _formComponentProviders;
public Dictionary<string, IFormComponentProvider> TypeToComponentProvider = new();
public FormComponentProviders(IEnumerable<IFormComponentProvider> formComponentProviders)
{
_formComponentProviders = formComponentProviders;
foreach (var prov in _formComponentProviders)
prov.Register(TypeToComponentProvider);
}
public bool Validate(Form form, ModelStateDictionary modelState)
{
foreach (var field in form.GetAllFields())
{
if (TypeToComponentProvider.TryGetValue(field.Field.Type, out var provider))
{
provider.Validate(form, field.Field);
foreach (var err in field.Field.ValidationErrors)
modelState.TryAddModelError(field.Field.Name, err);
}
}
return modelState.IsValid;
}
}