btcpayserver/BTCPayServer/Models/AppViewModels/CreateAppViewModel.cs

47 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 BTCPayServer.Plugins.PointOfSale;
2018-04-03 11:50:41 +09:00
using BTCPayServer.Services.Apps;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace BTCPayServer.Models.AppViewModels
{
public class CreateAppViewModel
{
public CreateAppViewModel()
{
}
public CreateAppViewModel(AppService appService)
2018-04-03 11:50:41 +09:00
{
SetApps(appService);
2018-04-03 11:50:41 +09:00
}
2018-04-03 11:50:41 +09:00
[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; }
private void SetApps(AppService appService)
2018-04-03 11:50:41 +09:00
{
var defaultAppType = PointOfSaleAppType.AppType;
var choices = appService.GetAvailableAppTypes().Select(pair =>
new SelectListItem(pair.Value, pair.Key, pair.Key == defaultAppType));
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.Text), chosen);
2018-04-03 11:50:41 +09:00
SelectedAppType = chosen.Value;
}
}
}