2022-11-02 10:21:33 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Linq;
|
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services.Stores;
|
|
|
|
|
|
|
|
public enum GenericFormOption
|
|
|
|
{
|
2023-01-06 14:18:07 +01:00
|
|
|
[Display(Name = "Do not request any information")]
|
|
|
|
None,
|
2022-11-02 10:21:33 +01:00
|
|
|
|
2023-01-06 14:18:07 +01:00
|
|
|
[Display(Name = "Request email address only")]
|
|
|
|
Email,
|
2022-11-02 10:21:33 +01:00
|
|
|
|
2023-01-06 14:18:07 +01:00
|
|
|
[Display(Name = "Request shipping address")]
|
|
|
|
Address
|
2022-11-02 10:21:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class CheckoutFormSelectList
|
|
|
|
{
|
2022-11-25 02:42:55 +01:00
|
|
|
public static SelectList WithSelected(string selectedFormId)
|
2022-11-02 10:21:33 +01:00
|
|
|
{
|
2022-11-25 02:42:55 +01:00
|
|
|
var choices = new List<SelectListItem>
|
2022-11-02 10:21:33 +01:00
|
|
|
{
|
2022-11-25 02:42:55 +01:00
|
|
|
GenericOptionItem(GenericFormOption.None),
|
|
|
|
GenericOptionItem(GenericFormOption.Email),
|
|
|
|
GenericOptionItem(GenericFormOption.Address)
|
|
|
|
};
|
2023-01-06 14:18:07 +01:00
|
|
|
|
2022-11-02 10:21:33 +01:00
|
|
|
var chosen = choices.FirstOrDefault(t => t.Value == selectedFormId);
|
|
|
|
return new SelectList(choices, nameof(SelectListItem.Value), nameof(SelectListItem.Text), chosen?.Value);
|
|
|
|
}
|
|
|
|
|
2023-01-06 14:18:07 +01:00
|
|
|
private static string DisplayName(GenericFormOption opt) =>
|
2022-11-02 10:21:33 +01:00
|
|
|
typeof(GenericFormOption).DisplayName(opt.ToString());
|
|
|
|
|
|
|
|
private static SelectListItem GenericOptionItem(GenericFormOption opt) =>
|
2022-11-28 20:50:09 +09:00
|
|
|
new() { Text = DisplayName(opt), Value = opt == GenericFormOption.None ? null : opt.ToString() };
|
2022-11-02 10:21:33 +01:00
|
|
|
}
|