btcpayserver/BTCPayServer/Models/AppViewModels/CreateAppViewModel.cs

51 lines
1.4 KiB
C#
Raw Normal View History

2018-04-03 11:50:41 +09:00
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
2018-04-03 11:50:41 +09:00
using BTCPayServer.Data;
using BTCPayServer.Services.Apps;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace BTCPayServer.Models.AppViewModels
{
public class CreateAppViewModel
{
public CreateAppViewModel()
{
SetApps();
}
class Format
{
public string Name { get; set; }
public string Value { get; set; }
}
[Required]
[MaxLength(50)]
[MinLength(1)]
2021-11-08 05:24:28 -08:00
[Display(Name = "App Name")]
public string AppName { get; set; }
2018-04-03 11:50:41 +09:00
[Display(Name = "Store")]
public string StoreId { get; set; }
2018-04-03 11:50:41 +09:00
2021-11-08 05:24:28 -08:00
[Display(Name = "App Type")]
2018-04-03 11:50:41 +09:00
public string SelectedAppType { get; set; }
public SelectList AppTypes { get; set; }
void SetApps()
{
var defaultAppType = AppType.PointOfSale.ToString();
var choices = typeof(AppType).GetEnumNames().Select(o => new Format
{
Name = typeof(AppType).DisplayName(o),
Value = o
}).ToArray();
2018-04-03 11:50:41 +09:00
var chosen = choices.FirstOrDefault(f => f.Value == defaultAppType) ?? choices.FirstOrDefault();
AppTypes = new SelectList(choices, nameof(chosen.Value), nameof(chosen.Name), chosen);
SelectedAppType = chosen.Value;
}
}
}